Class: Dry::Validation::Result
- Inherits:
-
Object
- Object
- Dry::Validation::Result
- Includes:
- Enumerable
- Defined in:
- lib/dry/validation/result.rb
Constant Summary collapse
- EMPTY_MESSAGES =
{}.freeze
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)
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.
- #messages(options = {}) ⇒ Object
- #success? ⇒ Boolean
- #to_ast ⇒ Object
Constructor Details
#initialize(output, errors, error_compiler, hint_compiler) ⇒ Result
Returns a new instance of Result.
16 17 18 19 20 21 |
# File 'lib/dry/validation/result.rb', line 16 def initialize(output, errors, error_compiler, hint_compiler) @output = output @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.
9 10 11 |
# File 'lib/dry/validation/result.rb', line 9 def error_compiler @error_compiler end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/dry/validation/result.rb', line 8 def errors @errors end |
#hint_compiler ⇒ Object (readonly)
Returns the value of attribute hint_compiler.
10 11 12 |
# File 'lib/dry/validation/result.rb', line 10 def hint_compiler @hint_compiler end |
#output ⇒ Object (readonly) Also known as: to_hash
Returns the value of attribute output.
7 8 9 |
# File 'lib/dry/validation/result.rb', line 7 def output @output end |
Instance Method Details
#[](name) ⇒ Object
27 28 29 |
# File 'lib/dry/validation/result.rb', line 27 def [](name) output.fetch(name) end |
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/dry/validation/result.rb', line 23 def each(&block) output.each(&block) end |
#failure? ⇒ Boolean
35 36 37 |
# File 'lib/dry/validation/result.rb', line 35 def failure? !success? end |
#messages(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dry/validation/result.rb', line 39 def ( = {}) @messages ||= begin return EMPTY_MESSAGES if success? hints = hint_compiler.with().call comp = error_compiler.with(.merge(hints: hints)) comp.(error_ast) end end |
#success? ⇒ Boolean
31 32 33 |
# File 'lib/dry/validation/result.rb', line 31 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 |