class PIM::ValidationResult

Attributes

all_messages[R]
calculated_values_by_attribute_name[R]
messages_by_attribute_name[R]
messages_by_level[R]
states_by_attribute_name[R]

Public Class Methods

new() click to toggle source
# File pim.rb, line 9170
def initialize
  @all_messages = []
  @messages_by_level = Hash.new { |h,k| h[k] = [] }
  @messages_by_attribute_name = Hash.new { |h,k| h[k] = [] }
  @states_by_attribute_name = Hash.new { |h,k| h[k] = [] }
  @calculated_values_by_attribute_name = {}
end

Public Instance Methods

add_attribute(attribute_name) click to toggle source
# File pim.rb, line 9178
def add_attribute attribute_name
  @messages_by_attribute_name[attribute_name] ||= []
end
add_attribute_states(attribute_name) click to toggle source
# File pim.rb, line 9182
def add_attribute_states attribute_name
  @states_by_attribute_name[attribute_name] ||= []
end
add_calculated_attribute(attribute_name) click to toggle source
# File pim.rb, line 9186
def add_calculated_attribute attribute_name
  @calculated_values_by_attribute_name[attribute_name] ||= nil
end
as_json() click to toggle source
# File pim.rb, line 9226
def as_json

  sorted_messages = Hash[@messages_by_attribute_name.sort]
  sorted_states = Hash[@states_by_attribute_name.sort]

  result = {}
  result[:validations] = PIM::Utils.as_json(sorted_messages)
  result[:attributeStates] = PIM::Utils.as_json(sorted_states) if !sorted_states.empty?
  result[:calculations] = PIM::Utils.as_json(@calculated_values_by_attribute_name) if !calculated_values_by_attribute_name.empty?
  result

end
enable_attribute_state(attribute_name, state) click to toggle source
# File pim.rb, line 9190
def enable_attribute_state attribute_name, state
  @states_by_attribute_name[attribute_name] << state if !@states_by_attribute_name[attribute_name].include?(state)
end
error?() click to toggle source
# File pim.rb, line 9214
def error?
  !@messages_by_level[PIM::ValidationLevel::ERROR].empty?
end
fail(rule, level, attribute_path, message, params = nil) click to toggle source
# File pim.rb, line 9200
def fail rule, level, attribute_path, message, params = nil
  attribute_name = attribute_path.first || ""
  message = PIM::ValidationMessage.new(rule.name, level, attribute_path, message, params)
  @all_messages << message
  @messages_by_level[level] << message
  @messages_by_attribute_name[attribute_name] << message
  message
end
failure?() click to toggle source
# File pim.rb, line 9218
def failure?
  !@messages_by_level[PIM::ValidationLevel::FAILURE].empty?
end
has_attribute_state?(attribute_name, state) click to toggle source
# File pim.rb, line 9194
def has_attribute_state? attribute_name, state
  return false if not @states_by_attribute_name.include?(attribute_name)
  states = (@states_by_attribute_name[attribute_name] || [])
  return (states.include?(state) or state.is_a?(Symbol) ? states.include?(state.to_s) : states.include?(state.to_s.to_sym))
end
length() click to toggle source
# File pim.rb, line 9209
def length
  @all_messages.length
end
Also aliased as: size
size()
Alias for: length
warning?() click to toggle source
# File pim.rb, line 9222
def warning?
  !@messages_by_level[PIM::ValidationLevel::WARNING].empty?
end