Module: FlickrawObjects::Attributes::ClassMethods
- Defined in:
- lib/flickraw_objects/attributes.rb
Instance Method Summary collapse
- #alias_method_chain(first_method, second_method) ⇒ Object
- #attribute(name, type: nil, path: []) ⇒ Object
- #attribute_source(value) ⇒ Object
Instance Method Details
#alias_method_chain(first_method, second_method) ⇒ Object
50 51 52 53 54 55 56 57 |
# 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: []) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/flickraw_objects/attributes.rb', line 27 def attribute_source(value) @attribute_source = value end |