Module: Wrest::Components::AttributesContainer::ClassMethods
- Defined in:
- lib/wrest/components/attributes_container.rb
Instance Method Summary collapse
-
#always_has(*attribute_names) ⇒ Object
This macro explicitly creates getter, setter and query methods on a class, overriding any exisiting methods with the same names.
Instance Method Details
#always_has(*attribute_names) ⇒ Object
This macro explicitly creates getter, setter and query methods on a class, overriding any exisiting methods with the same names. This can be used when attribute names clash with method names; an example would be Rails REST services which frequently make use an attribute named id
which clashes with Object#id. Also, this can be used as a performance optimisation if the incoming attributes are known beforehand.
83 84 85 86 87 88 89 90 91 |
# File 'lib/wrest/components/attributes_container.rb', line 83 def always_has(*attribute_names) attribute_names.each do |attribute_name| self.class_eval( AttributesContainer.build_attribute_getter(attribute_name) + AttributesContainer.build_attribute_setter(attribute_name) + AttributesContainer.build_attribute_queryer(attribute_name) ) end end |