Class: Dry::Validation::Schema::Result
- Inherits:
-
Object
- Object
- Dry::Validation::Schema::Result
- Includes:
- Enumerable
- Defined in:
- lib/dry/validation/schema/result.rb
Instance Attribute Summary collapse
-
#error_compiler ⇒ Object
readonly
Returns the value of attribute error_compiler.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#hint_compiler ⇒ Object
readonly
Returns the value of attribute hint_compiler.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #failures ⇒ Object
-
#initialize(params, result, errors, error_compiler, hint_compiler) ⇒ Result
constructor
A new instance of Result.
- #messages(options = {}) ⇒ Object
- #successes ⇒ Object
- #to_ary ⇒ Object
Constructor Details
#initialize(params, result, errors, error_compiler, hint_compiler) ⇒ Result
Returns a new instance of Result.
17 18 19 20 21 22 23 |
# File 'lib/dry/validation/schema/result.rb', line 17 def initialize(params, result, errors, error_compiler, hint_compiler) @params = params @result = result @errors = errors @error_compiler = error_compiler @hint_compiler = hint_compiler end |
Instance Attribute Details
#error_compiler ⇒ Object (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 |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/dry/validation/schema/result.rb', line 11 def errors @errors end |
#hint_compiler ⇒ Object (readonly)
Returns the value of attribute hint_compiler.
15 16 17 |
# File 'lib/dry/validation/schema/result.rb', line 15 def hint_compiler @hint_compiler end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/dry/validation/schema/result.rb', line 7 def params @params end |
#result ⇒ Object (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
25 26 27 |
# File 'lib/dry/validation/schema/result.rb', line 25 def each(&block) failures.each(&block) end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/dry/validation/schema/result.rb', line 29 def empty? errors.empty? end |
#failures ⇒ Object
63 64 65 |
# File 'lib/dry/validation/schema/result.rb', line 63 def failures result.failures end |
#messages(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dry/validation/schema/result.rb', line 37 def ( = {}) @messages ||= begin all_msgs = error_compiler.with().(errors.map(&:to_ary)) hints = hint_compiler.with().call msgs_data = all_msgs.map do |(name, data)| msgs, input = if data.is_a?(Hash) values = data.values [values.map(&:first).flatten.concat(hints[name]).uniq, values[0][1]] else [data[0].concat(hints[name]).uniq.flatten, data[1]] end [name, [msgs, input]] end Hash[msgs_data] end end |
#successes ⇒ Object
59 60 61 |
# File 'lib/dry/validation/schema/result.rb', line 59 def successes result.successes end |
#to_ary ⇒ Object
33 34 35 |
# File 'lib/dry/validation/schema/result.rb', line 33 def to_ary errors.map(&:to_ary) end |