class PIM::AttributeModifier

Public Class Methods

create_multi_param(param, *default_values) click to toggle source
# File pim.rb, line 4464
def self.create_multi_param param, *default_values
  define_method param do |*values|
    values = values.flatten.compact
    values = default_values if values.empty?
    values = nil if values.empty?
    @params[param] = values
  end
  private param
end
create_param(param, default_value = nil) click to toggle source
# File pim.rb, line 4455
def self.create_param param, default_value = nil
  define_method param do |*values|
    value = values.first
    value = default_value if value.nil?
    @params[param] = value
  end
  private param
end
new(name, params = {}) click to toggle source
# File pim.rb, line 4474
def initialize name, params = {}, states = {}
  @name = name
  @params = params
  @states = states
end

Public Instance Methods

calculate(*dependent_attributes, &block) click to toggle source
# File pim.rb, line 4494
def calculate *dependent_attributes, &block
  formula = PIM::CalculationFormula.new
  formula.dependent_attributes = dependent_attributes
  formula.calculated_attribute = @name
  formula.block = block
  data_module.add_formula(formula)
end
custom_param(name, value = nil) click to toggle source
# File pim.rb, line 4513
def custom_param name, value = nil
  @params[:custom] ||= {}
  @params[:custom][to_sym(name)] = value
end
direct_publication(enabled = true, from: nil, to: nil) click to toggle source
# File pim.rb, line 4502
def direct_publication enabled = true, from: nil, to: nil
  @params[:direct_publications] ||= []
  @params[:direct_publications] << PIM::DirectPublication.create(enabled, from: from, to: to)
end
direct_publication_targets(*values) click to toggle source
# File pim.rb, line 4507
def direct_publication_targets *values
  @params[:direct_publications] ||= []
  @params[:direct_publications] << PIM::DirectPublication.create(true, to: values)
  @params[:direct_publications] << PIM::DirectPublication.create(false)
end
state(state_name, *dependent_attributes, &block) click to toggle source
# File pim.rb, line 4480
def state state_name, *dependent_attributes, &block
  state_name = to_sym(state_name)
  dependent_attributes.each do |dependent_attribute|
    data_module.check_attribute!(dependent_attribute,
                                 "Dependent attribute '#{dependent_attribute}' used in state '#{state_name}' for attribute '#{@name}' is not defined")
  end
  state = {
    :name => state_name,
    :dependent_attributes => dependent_attributes,
    :block => block
  }
  @states[state_name] = state
end