diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-05-18 15:33:54 +0200 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-05-18 15:33:54 +0200 |
commit | 2ebafdfb2f026580153fd2cf50f4b6b7ab3a0344 (patch) | |
tree | f279da514fda13303db113d54af29c7fc200c34f | |
parent | 17c4e53e80af6c652f427733dc7dce4b7f88c8b6 (diff) | |
download | gitlab-ce-2ebafdfb2f026580153fd2cf50f4b6b7ab3a0344.tar.gz |
Improve cacheable module
-rw-r--r-- | app/models/concerns/redis_cacheable.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/concerns/redis_cacheable.rb b/app/models/concerns/redis_cacheable.rb index b5425295130..53f022e2b35 100644 --- a/app/models/concerns/redis_cacheable.rb +++ b/app/models/concerns/redis_cacheable.rb @@ -7,11 +7,11 @@ module RedisCacheable class_methods do def cached_attr_reader(*attributes) attributes.each do |attribute| - define_method(attribute) do - unless self.has_attribute?(attribute) - raise ArgumentError, "`cached_attr_reader` requires the #{self.class.name}\##{attribute} attribute to have a database column" - end + unless self.column_names.include?(attribute.to_s) + raise ArgumentError, "`cached_attr_reader` requires the #{self.name}##{attribute} to be a database attribute" + end + define_method(attribute) do cached_attribute(attribute) || read_attribute(attribute) end end @@ -50,7 +50,9 @@ module RedisCacheable if Gitlab.rails5? self.class.type_for_attribute(attribute).cast(value) else - self.class.column_for_attribute(attribute).type_cast_from_database(value) + ActiveSupport::Deprecation.silence do + self.class.column_for_attribute(attribute).type_cast_from_database(value) + end end end end |