lib/redd/models/basic_model.rb in redd-0.8.0.pre.1 vs lib/redd/models/basic_model.rb in redd-0.8.0.pre.2
- old
+ new
@@ -59,19 +59,19 @@
# Checks whether an attribute is supported by method_missing.
# @param method_name [Symbol] the method name or attribute to check
# @param include_private [Boolean] whether to also include private methods
# @return [Boolean] whether the method is handled by method_missing
def respond_to_missing?(method_name, include_private = false)
- attribute?(method_name) || attribute?(depredicate(method_name)) || super
+ @attributes.key?(method_name) || @attributes.key?(depredicate(method_name)) || super
end
# Return an attribute or raise a NoMethodError if it doesn't exist.
# @param method_name [Symbol] the name of the attribute
# @return [Object] the result of the attribute check
def method_missing(method_name, *args, &block)
- return get_attribute(method_name) if attribute?(method_name)
- return get_attribute(depredicate(method_name)) if attribute?(depredicate(method_name))
+ return get_attribute(method_name) if @attributes.key?(method_name)
+ return get_attribute(depredicate(method_name)) if @attributes.key?(depredicate(method_name))
super
end
private
@@ -110,15 +110,9 @@
def get_attribute(name)
# Coerce the attribute if it exists and needs to be coerced.
coerce_attribute(name) if @to_coerce.include?(name) && @attributes.key?(name)
# Fetch the attribute, raising a KeyError if it doesn't exist.
@attributes.fetch(name)
- end
-
- # @param name [Symbol] the name of the attribute to check
- # @return [Boolean] whether the attribute exists
- def attribute?(name)
- @attributes.key?(name)
end
end
end
end