Class: RSchema::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/rschema/error.rb

Overview

Contains info about how a schema failed validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema:, value:, symbolic_name:, vars: {}) ⇒ Error

Returns a new instance of Error

Raises:

  • (ArgumentError)

10
11
12
13
14
15
16
17
18
19
# File 'lib/rschema/error.rb', line 10

def initialize(schema:, value:, symbolic_name:, vars: {})
  raise ArgumentError.new('vars must be a hash') unless vars.is_a?(Hash)

  @schema = schema
  @value = value
  @symbolic_name = symbolic_name
  @vars = vars

  freeze
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema


8
9
10
# File 'lib/rschema/error.rb', line 8

def schema
  @schema
end

#symbolic_nameObject (readonly)

Returns the value of attribute symbolic_name


8
9
10
# File 'lib/rschema/error.rb', line 8

def symbolic_name
  @symbolic_name
end

#valueObject (readonly)

Returns the value of attribute value


8
9
10
# File 'lib/rschema/error.rb', line 8

def value
  @value
end

#varsObject (readonly)

Returns the value of attribute vars


8
9
10
# File 'lib/rschema/error.rb', line 8

def vars
  @vars
end

Instance Method Details

#inspectObject


25
26
27
28
29
30
31
# File 'lib/rschema/error.rb', line 25

def inspect
  attrs = vars.merge(value: value)
              .map { |k, v| "#{k}=#{v.inspect}" }
              .join(' ')

  "<#{self.class} #{self} #{attrs}>"
end

#to_sObject


21
22
23
# File 'lib/rschema/error.rb', line 21

def to_s
  "#{schema.class}/#{symbolic_name}"
end