Exception: Meta::JsonSchema::ValidationErrors

Inherits:
StandardError
  • Object
show all
Defined in:
lib/meta/json_schema/support/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, message = nil) ⇒ ValidationErrors

Returns a new instance of ValidationErrors.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
# File 'lib/meta/json_schema/support/errors.rb', line 8

def initialize(errors, message = nil)
  raise ArgumentError, '参数 errors 应传递一个 Hash' unless errors.is_a?(Hash)

  super(message)
  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/meta/json_schema/support/errors.rb', line 6

def errors
  @errors
end

Instance Method Details

#prepend_root(root) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/meta/json_schema/support/errors.rb', line 15

def prepend_root(root)
  errors_prepend_root = errors.transform_keys do |name|
    return name.to_s if root.empty?

    path = name[0] == '[' ? "#{root}#{name}" : "#{root}.#{name}"
    path = path[1..] if path[0] == '.'
    path = path[0..-2] if path[-1] == '.'
    path
  end
  ValidationErrors.new(errors_prepend_root)
end