class Object

Public Class Methods

for_custom_attribute_definition(custom_attribute_defn, owner) click to toggle source
# File lib/generators/custom_attributes/templates/custom_attribute_value_model.rb, line 11
def self.for_custom_attribute_definition (custom_attribute_defn, owner)
  if custom_attribute_defn.nil? || owner.nil?
    return nil
  end

  custom_attr_value = case custom_attribute_defn.attr_type
  when CustomAttributes::CustomAttribute::TYPE_NUMBER
    <% name %>CustomAttributeIntegerValue.new(custom_attribute_defn: custom_attribute_defn, owner: owner)
  when CustomAttributes::CustomAttribute::TYPE_DECIMAL
    <% name %>CustomAttributeDoubleValue.new(custom_attribute_defn: custom_attribute_defn, owner: owner)
  when CustomAttributes::CustomAttribute::TYPE_DATE, CustomAttributes::CustomAttribute::TYPE_DATE_TIME
    <% name %>CustomAttributeDateTimeValue.new(custom_attribute_defn: custom_attribute_defn, owner: owner)
  when CustomAttributes::CustomAttribute::TYPE_TEXT, CustomAttributes::CustomAttribute::TYPE_MULTILINE_TEXT
    <% name %>CustomAttributeStringValue.new(custom_attribute_defn: custom_attribute_defn, owner: owner)
  else
    nil
  end

  custom_attr_value
end

Public Instance Methods

add_custom_attributes_with_default_values() click to toggle source
# File lib/generators/custom_attributes/templates/custom_attributes_concern.rb, line 10
def add_custom_attributes_with_default_values
  return unless self.new_record?
  return if self.custom_attributes.blank?
  self.custom_attributes.each do |cav|
    unless cav.custom_attribute_defn.default_value.blank?
      self.custom_attribute_values.push(cav)
    end
  end
end
custom_attributes() click to toggle source
# File lib/generators/custom_attributes/templates/custom_attributes_concern.rb, line 41
def custom_attributes
<% if options.tenant %>
  custom_attribute_defns = <%= name %>CustomAttributeDefinition.all.current_tenant(<%= options.tenant %>_id)
  custom_attribute_defns.collect { |defn|
    custom_attribute_values.current_tenant(<%= options.tenant %>_id).find { |cv| cv.custom_attribute_defn==defn } || <%= name %>CustomAttributeValue.initialize(defn, self)
  }
<% else %>
  custom_attribute_defns = <%= name %>CustomAttributeDefinition.all
  custom_attribute_defns.collect { |defn|
    custom_attribute_values.find { |cv| cv.custom_attribute_defn==defn } || <
custom_attributes=(map_of_custom_attributes) click to toggle source
# File lib/generators/custom_attributes/templates/custom_attributes_concern.rb, line 20
def custom_attributes=(map_of_custom_attributes)
  return if map_of_custom_attributes.nil?

  map_of_custom_attributes.each do |key, value|
    custom_attribute_value = custom_attribute_values.find { |cav| cav.name==key }
    if not custom_attribute_value
<% if options.tenant %>
      custom_attribute_defns  = <%= name %>CustomAttributeDefinition.all.current_tenant(<%= options.tenant %>_id)
      # Uncomment the following if you have defined a default_scope for <%= name %>CustomAttributeDefinition
      # custom_attribute_defns = <%= name %>CustomAttributeDefinition.all
<% else %>
      custom_attribute_defns  = <%= name %>CustomAttributeDefinition.all
<% end %>
      custom_attribute_defn   = custom_attribute_defns.find { |cad| cad.attr_name == key }
      custom_attribute_value  = <%= name %>CustomAttributeValue.initialize(custom_attribute_defn, self)
      self.custom_attribute_values.push(custom_attribute_value)
    end
    custom_attribute_value.value = value
  end
end

def custom_attributes
<% if options.tenant %>
  custom_attribute_defns = <%= name %>CustomAttributeDefinition.all.current_tenant(<%= options.tenant %>_id)
  custom_attribute_defns.collect { |defn|
    custom_attribute_values.current_tenant(<%= options.tenant %>_id).find { |cv| cv.custom_attribute_defn==defn } || <%= name %>CustomAttributeValue.initialize(defn, self)
  }
<% else %>
  custom_attribute_defns = <%= name %>CustomAttributeDefinition.all
  custom_attribute_defns.collect { |defn|
    custom_attribute_values.find { |cv| cv.custom_attribute_defn==defn } ||