Move argument check to cached getter definition class method
This commit is contained in:
parent
a4b0876b39
commit
4e1bb1d101
2 changed files with 4 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue