Commit 4e1bb1d1 authored by Matija Čupić's avatar Matija Čupić

Move argument check to cached getter definition class method

parent a4b0876b
...@@ -7,9 +7,9 @@ module RedisCacheable ...@@ -7,9 +7,9 @@ module RedisCacheable
class_methods do class_methods do
def cached_attr_reader(*attributes) def cached_attr_reader(*attributes)
attributes.each do |attribute| attributes.each do |attribute|
define_method(attribute) do raise ArgumentError, "Not a database attribute" unless self.attribute_names.include?(attribute.to_s)
raise ArgumentError, "Not a database attribute" unless self.has_attribute?(attribute)
define_method(attribute) do
cached_attribute(attribute) || read_attribute(attribute) cached_attribute(attribute) || read_attribute(attribute)
end end
end end
......
...@@ -11,8 +11,8 @@ describe RedisCacheable do ...@@ -11,8 +11,8 @@ describe RedisCacheable do
cached_value cached_value
end end
def has_attribute?(attribute) def self.attribute_names
attributes.has_key?(attribute) %w[name time]
end end
end 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