Class: RSchema::Error

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

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)

5
6
7
8
9
10
11
12
13
14
# File 'lib/rschema/error.rb', line 5

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


3
4
5
# File 'lib/rschema/error.rb', line 3

def schema
  @schema
end

#symbolic_nameObject (readonly)

Returns the value of attribute symbolic_name


3
4
5
# File 'lib/rschema/error.rb', line 3

def symbolic_name
  @symbolic_name
end

#valueObject (readonly)

Returns the value of attribute value


3
4
5
# File 'lib/rschema/error.rb', line 3

def value
  @value
end

#varsObject (readonly)

Returns the value of attribute vars


3
4
5
# File 'lib/rschema/error.rb', line 3

def vars
  @vars
end

Instance Method Details

#inspectObject


20
21
22
23
24
25
26
# File 'lib/rschema/error.rb', line 20

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

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

#to_sObject


16
17
18
# File 'lib/rschema/error.rb', line 16

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