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