Commit a4b0876b authored by Matija Čupić's avatar Matija Čupić

Add attribute check in cached getter

parent 42ab6f85
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment