module CustomAttributes

Constants

VERSION

Public Instance Methods

custom_attributes() click to toggle source
# File lib/custom_attributes.rb, line 23
def custom_attributes
  custom_attribute_defns = self.class.allowed_custom_attributes
  custom_attribute_defns.collect { |defn|
    custom_attribute_values.find { |cv| cv.custom_attribute==defn } || CustomAttributeValue.new(custom_attribute: defn)
  }
end
custom_attributes=(map_of_custom_attributes) click to toggle source
# File lib/custom_attributes.rb, line 10
def custom_attributes=(map_of_custom_attributes)
  map_of_custom_attributes.each do |key, value|
    custom_attribute_value = custom_attribute_values.find { |cav| cav.name==key }
    if not custom_attribute_value
      custom_attribute = self.class.allowed_custom_attributes.find { |ca| ca.attr_name == key }
      #TODO: Reuse the .new method below. Also change it to a Factory like pattern
      custom_attribute_value = CustomAttributeValue.new(custom_attribute: custom_attribute)
      self.custom_attribute_values.push(custom_attribute_value)
    end
    custom_attribute_value.value = value
  end
end