Class: Reform::Contract::Result
- Inherits:
-
Object
- Object
- Reform::Contract::Result
- Defined in:
- lib/reform/result.rb
Overview
Collects all native results of a form of all groups and provides a unified API: #success?, #errors, #messages, #hints. #success? returns validity of the branch.
Defined Under Namespace
Instance Method Summary collapse
- #add_error(key, error_text) ⇒ Object
- #errors(*args) ⇒ Object
- #failure? ⇒ Boolean
- #hints(*args) ⇒ Object
-
#initialize(results, nested_results = []) ⇒ Result
constructor
DISCUSS: do we like this?.
- #messages(*args) ⇒ Object
- #success? ⇒ Boolean
- #to_results ⇒ Object
Constructor Details
#initialize(results, nested_results = []) ⇒ Result
DISCUSS: do we like this?
7 8 9 10 |
# File 'lib/reform/result.rb', line 7 def initialize(results, nested_results = []) # DISCUSS: do we like this? @results = results # native Result objects, e.g. `#<Dry::Validation::Result output={:title=>"Fallout", :composer=>nil} errors={}>` @failure = (results + nested_results).find(&:failure?) # TODO: test nested. end |
Instance Method Details
#add_error(key, error_text) ⇒ Object
22 23 24 |
# File 'lib/reform/result.rb', line 22 def add_error(key, error_text) CustomError.new(key, error_text, @results) end |
#errors(*args) ⇒ Object
16 |
# File 'lib/reform/result.rb', line 16 def errors(*args); filter_for(:errors, *args) end |
#failure? ⇒ Boolean
12 |
# File 'lib/reform/result.rb', line 12 def failure?; @failure end |
#hints(*args) ⇒ Object
20 |
# File 'lib/reform/result.rb', line 20 def hints(*args); filter_for(:hints, *args) end |
#messages(*args) ⇒ Object
18 |
# File 'lib/reform/result.rb', line 18 def (*args); filter_for(:messages, *args) end |
#success? ⇒ Boolean
14 |
# File 'lib/reform/result.rb', line 14 def success?; !failure? end |
#to_results ⇒ Object
26 27 28 |
# File 'lib/reform/result.rb', line 26 def to_results @results end |