Add attribute check in cached getter
This commit is contained in:
parent
42ab6f8557
commit
a4b0876b39
|
@ -8,6 +8,8 @@ module RedisCacheable
|
|||
def cached_attr_reader(*attributes)
|
||||
attributes.each do |attribute|
|
||||
define_method(attribute) do
|
||||
raise ArgumentError, "Not a database attribute" unless self.has_attribute?(attribute)
|
||||
|
||||
cached_attribute(attribute) || read_attribute(attribute)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ describe RedisCacheable do
|
|||
def cast_value_from_cache(attribute, cached_value)
|
||||
cached_value
|
||||
end
|
||||
|
||||
def has_attribute?(attribute)
|
||||
attributes.has_key?(attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue