Class: Dry::Validation::Schema::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dry/validation/schema/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, result, errors, error_compiler) ⇒ Result

Returns a new instance of Result.



15
16
17
18
19
20
# File 'lib/dry/validation/schema/result.rb', line 15

def initialize(params, result, errors, error_compiler)
  @params = params
  @result = result
  @errors = errors
  @error_compiler = error_compiler
end

Instance Attribute Details

#error_compilerObject (readonly)

Returns the value of attribute error_compiler.



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

def error_compiler
  @error_compiler
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/dry/validation/schema/result.rb', line 11

def errors
  @errors
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/dry/validation/schema/result.rb', line 7

def params
  @params
end

#resultObject (readonly)

Returns the value of attribute result.



9
10
11
# File 'lib/dry/validation/schema/result.rb', line 9

def result
  @result
end

Instance Method Details

#each(&block) ⇒ Object



22
23
24
# File 'lib/dry/validation/schema/result.rb', line 22

def each(&block)
  failures.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dry/validation/schema/result.rb', line 26

def empty?
  errors.empty?
end

#failuresObject



42
43
44
# File 'lib/dry/validation/schema/result.rb', line 42

def failures
  result.failures
end

#messages(options = {}) ⇒ Object



34
35
36
# File 'lib/dry/validation/schema/result.rb', line 34

def messages(options = {})
  @messages ||= error_compiler.with(options).(errors.map(&:to_ary))
end

#successesObject



38
39
40
# File 'lib/dry/validation/schema/result.rb', line 38

def successes
  result.successes
end

#to_aryObject



30
31
32
# File 'lib/dry/validation/schema/result.rb', line 30

def to_ary
  errors.map(&:to_ary)
end