Module: Wrest::Components::AttributesContainer::ClassMethods

Defined in:
lib/wrest/components/attributes_container.rb

Instance Method Summary collapse

Instance Method Details

#has_attributes(*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, as defining methods on the first invocation is no longer necessary.



64
65
66
67
68
69
70
71
72
# File 'lib/wrest/components/attributes_container.rb', line 64

def has_attributes(*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