Class: Dry::Validation::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, result) ⇒ Error

Returns a new instance of Error.



8
9
10
11
# File 'lib/dry/validation/error.rb', line 8

def initialize(name, result)
  @name = name
  @result = result
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/dry/validation/error.rb', line 6

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/dry/validation/error.rb', line 6

def result
  @result
end

Instance Method Details

#schema?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dry/validation/error.rb', line 13

def schema?
  result.response.is_a?(Validation::Result)
end

#to_astObject



17
18
19
20
21
22
23
# File 'lib/dry/validation/error.rb', line 17

def to_ast
  if schema?
    [:schema, [name, result.response.to_ast]]
  else
    [:error, [name, result.to_ast]]
  end
end