class PIM::ValidationContext

Attributes

additional_category_attributes[R]
attribute[R]
attribute_path[R]
cache[R]
data_model[R]
item[R]
new_item[R]
new_parent_value[R]
new_value[R]
new_values[R]
old_item[R]
old_parent_value[R]
old_value[R]
old_values[R]
parent_value[R]
result[R]
rule[R]
value[R]
values[R]

Public Class Methods

new(data_model, result, rule, attribute, attribute_path, values_context = {}) click to toggle source
# File pim.rb, line 9015
def initialize data_model, result, rule, attribute, attribute_path, values_context = {}
  @data_model = data_model
  @result = result
  @rule = rule
  @attribute = attribute
  @attribute_path = attribute_path
  @old_item = values_context[:old_item]
  @new_item = values_context[:new_item]
  @old_values = values_context[:old_values]
  @new_values = values_context[:new_values]
  @old_value = values_context[:old_value]
  @new_value = values_context[:new_value]
  @old_parent_value = values_context[:old_parent_value]
  @new_parent_value = values_context[:new_parent_value]
  @additional_category_attributes = values_context[:additional_category_attributes]
  @cache = values_context[:cache] || {}
end

Public Instance Methods

attribute_param(name) click to toggle source
# File pim.rb, line 9055
def attribute_param name
  @attribute.param(name)
end
enum_validate(enum = nil, &validate_block) click to toggle source
# File pim.rb, line 9070
def enum_validate enum = nil, &validate_block
  if enum
    enum.each do |v|
      validate_value v, &validate_block
    end
  elsif attribute.base_class == Array
    value.each_with_index do |v, i|
      validate_value v, { :err_row => i }, &validate_block
    end
  elsif attribute.base_class == Hash
    value.each_pair do |k, v|
      validate_value v, (attribute.type_name == 'Physical' ? { :err_unit => k}  : { :err_key => k }), &validate_block
    end
  else
    validate_value value, &validate_block
  end
end
error(message, params = nil) click to toggle source
# File pim.rb, line 9042
def error message, params = nil
  fail_rule(PIM::ValidationLevel::ERROR, message, params)
end
failure(message, params = nil) click to toggle source
# File pim.rb, line 9038
def failure message, params = nil
  fail_rule(PIM::ValidationLevel::FAILURE, message, params)
end
location_msg() click to toggle source
# File pim.rb, line 9059
def location_msg
  @data_model.location_msg @attribute_path
end
merge_params(params, add_params) click to toggle source
# File pim.rb, line 9063
def merge_params params, add_params
  return params if !add_params
  params = (params || {})
  add_params.each_pair { |k,v| params[k] = v if !params.has_key?(k) }
  params
end
warn(message, params = nil)
Alias for: warning
warning(message, params = nil) click to toggle source
# File pim.rb, line 9033
def warning message, params = nil
  fail_rule(PIM::ValidationLevel::WARNING, message, params)
end
Also aliased as: warn