class PIM::AttributeModifier
Public Class Methods
create_multi_param(param, *default_values)
click to toggle source
# File pim.rb, line 4774 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 4765 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 4784 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 4804 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 4823 def custom_param name, value = nil @params[:custom] ||= {} @params[:custom][to_sym(name)] = value end
direct_publication(enabled = true, **kwargs)
click to toggle source
# File pim.rb, line 4812 def direct_publication enabled = true, **kwargs @params[:direct_publications] ||= [] @params[:direct_publications] << PIM::DirectPublication.create(enabled, **kwargs) end
direct_publication_targets(*values)
click to toggle source
# File pim.rb, line 4817 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 4790 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