Module: Kwalify::ErrorHelper

Included in:
Kwalify, Rule, Validator
Defined in:
lib/kwalify/errors.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._build_message(message_key, val, args) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/kwalify/errors.rb', line 114

def _build_message(message_key, val, args)
  msg = Kwalify.msg(message_key)
  assert_error("message_key=#{message_key.inspect}") unless msg
  msg = msg % args if args
  msg = "'#{val.to_s.gsub(/\n/, '\n')}': #{msg}" if !val.nil? && Types.scalar?(val)
  return msg;
end

.validate_error(error_symbol, rule, path, val, args = nil) ⇒ Object



101
102
103
104
105
# File 'lib/kwalify/errors.rb', line 101

def validate_error(error_symbol, rule, path, val, args=nil)
  msg = _build_message(error_symbol, val, args);
  path = '/'+path.join('/') if path.is_a?(Array)
  return ValidationError.new(msg, path, val, rule, error_symbol)
end

Instance Method Details

#assert_error(message = "") ⇒ Object

module_function

Raises:



97
98
99
# File 'lib/kwalify/errors.rb', line 97

def assert_error(message="")
  raise AssertionError.new(message)
end

#schema_error(error_symbol, rule, path, val, args = nil) ⇒ Object



108
109
110
111
112
# File 'lib/kwalify/errors.rb', line 108

def schema_error(error_symbol, rule, path, val, args=nil)
  msg = _build_message(error_symbol, val, args);
  path = '/'+path.join('/') if path.is_a?(Array)
  return SchemaError.new(msg, path, val, rule, error_symbol)
end