Class: Reform::Contract::Result::Pointer
- Inherits:
-
Object
- Object
- Reform::Contract::Result::Pointer
- Extended by:
- Forwardable
- Defined in:
- lib/reform/result.rb
Overview
Note: this class will be redundant in Reform 3, where the public API allows/enforces to pass options to #errors (e.g. errors(locale: “br”)) which means we don’t have to “lazy-handle” that with “pointers”. :private:
Instance Method Summary collapse
- #advance(*path) ⇒ Object
- #errors(*args) ⇒ Object
- #hints(*args) ⇒ Object
-
#initialize(result, path) ⇒ Pointer
constructor
A new instance of Pointer.
- #messages(*args) ⇒ Object
Constructor Details
#initialize(result, path) ⇒ Pointer
Returns a new instance of Pointer.
52 53 54 |
# File 'lib/reform/result.rb', line 52 def initialize(result, path) @result, @path = result, path end |
Instance Method Details
#advance(*path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/reform/result.rb', line 64 def advance(*path) path = @path + path.compact # remove index if nil. traverse = traverse(@result.errors, path) # when returns {} is because no errors are found # when returns a String is because an error has been found on the main key not in the nested one. # Collection with custom rule will return a String here and does not need to be considered # as a nested error. # when return an Array without an index is same as String but it's a property with a custom rule. # Check test/validation/dry_validation_test.rb:685 return if traverse == {} || traverse.is_a?(String) || (traverse.is_a?(Array) && path.compact.size == 1) Pointer.new(@result, path) end |
#errors(*args) ⇒ Object
58 |
# File 'lib/reform/result.rb', line 58 def errors(*args); traverse_for(:errors, *args) end |
#hints(*args) ⇒ Object
62 |
# File 'lib/reform/result.rb', line 62 def hints(*args); traverse_for(:hints, *args) end |
#messages(*args) ⇒ Object
60 |
# File 'lib/reform/result.rb', line 60 def (*args); traverse_for(:messages, *args) end |