Class: Dry::Validation::Result
- Inherits:
-
Object
- Object
- Dry::Validation::Result
- Includes:
- Enumerable
- Defined in:
- lib/dry/validation/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.
-
#output ⇒ Object
(also: #to_hash, #to_h)
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #each(&block) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(output, errors, error_compiler, hint_compiler) ⇒ Result
constructor
A new instance of Result.
- #message_set(options = EMPTY_HASH) ⇒ Object
- #messages(options = EMPTY_HASH) ⇒ Object
- #success? ⇒ Boolean
- #to_ast ⇒ Object
Constructor Details
#initialize(output, errors, error_compiler, hint_compiler) ⇒ Result
Returns a new instance of Result.
17 18 19 20 21 22 23 |
# File 'lib/dry/validation/result.rb', line 17 def initialize(output, errors, error_compiler, hint_compiler) @output = output @errors = errors @error_compiler = error_compiler @hint_compiler = hint_compiler @messages = EMPTY_HASH if success? end |
Instance Attribute Details
#error_compiler ⇒ Object (readonly)
Returns the value of attribute error_compiler.
11 12 13 |
# File 'lib/dry/validation/result.rb', line 11 def error_compiler @error_compiler end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/dry/validation/result.rb', line 10 def errors @errors end |
#hint_compiler ⇒ Object (readonly)
Returns the value of attribute hint_compiler.
12 13 14 |
# File 'lib/dry/validation/result.rb', line 12 def hint_compiler @hint_compiler end |
#output ⇒ Object (readonly) Also known as: to_hash, to_h
Returns the value of attribute output.
9 10 11 |
# File 'lib/dry/validation/result.rb', line 9 def output @output end |
Instance Method Details
#[](name) ⇒ Object
29 30 31 |
# File 'lib/dry/validation/result.rb', line 29 def [](name) output.fetch(name) end |
#each(&block) ⇒ Object
25 26 27 |
# File 'lib/dry/validation/result.rb', line 25 def each(&block) output.each(&block) end |
#failure? ⇒ Boolean
37 38 39 |
# File 'lib/dry/validation/result.rb', line 37 def failure? !success? end |
#message_set(options = EMPTY_HASH) ⇒ Object
45 46 47 48 49 |
# File 'lib/dry/validation/result.rb', line 45 def ( = EMPTY_HASH) error_compiler .with().(error_ast) .with_hints!(hint_compiler.with().()) end |
#messages(options = EMPTY_HASH) ⇒ Object
41 42 43 |
# File 'lib/dry/validation/result.rb', line 41 def ( = EMPTY_HASH) ().dump end |
#success? ⇒ Boolean
33 34 35 |
# File 'lib/dry/validation/result.rb', line 33 def success? errors.empty? end |
#to_ast ⇒ Object
51 52 53 |
# File 'lib/dry/validation/result.rb', line 51 def to_ast [:set, error_ast] end |