module FlickrawObjects::Attributes::ClassMethods
Public Instance Methods
alias_method_chain(first_method, second_method)
click to toggle source
# File lib/flickraw_objects/attributes.rb, line 50 def alias_method_chain(first_method, second_method) define_method("#{second_method}_with_#{first_method}") do method(first_method).call method("#{second_method}_without_#{first_method}").call end alias_method "#{second_method}_without_#{first_method}", second_method alias_method second_method, "#{second_method}_with_#{first_method}" end
attribute(name, type: nil, path: [])
click to toggle source
# File lib/flickraw_objects/attributes.rb, line 31 def attribute(name, type: nil, path: []) source = "@#{(@attribute_source || :init)}" define_method(name) do response = instance_variable_get(source) if path.empty? value = response.send name else value = path.inject(response) {|result, element| result.send element} end COERCIONS.fetch(type || String).call(value) end alias_method "#{name}?", name if type == Boolean if @attribute_source alias_method_chain(@attribute_source, name) end name end
attribute_source(value)
click to toggle source
# File lib/flickraw_objects/attributes.rb, line 27 def attribute_source(value) @attribute_source = value end