Move argument check to cached getter definition class method

This commit is contained in:
Matija Čupić 2018-05-16 21:49:09 +02:00
parent a4b0876b39
commit 4e1bb1d101
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
2 changed files with 4 additions and 4 deletions

View file

@ -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

View file

@ -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