Class: Interactor::Validation::Errors
- Includes:
- Enumerable
- Defined in:
- lib/interactor/validation/errors.rb
Overview
Minimal error collection
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #add(attribute, type = :invalid, message: nil, **options) ⇒ Object
- #any? ⇒ Boolean
- #clear ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(halt_checker: nil) ⇒ Errors
constructor
A new instance of Errors.
- #to_a ⇒ Object
Constructor Details
#initialize(halt_checker: nil) ⇒ Errors
Returns a new instance of Errors.
11 12 13 14 |
# File 'lib/interactor/validation/errors.rb', line 11 def initialize(halt_checker: nil) @errors = [] @halt_checker = halt_checker end |
Instance Method Details
#add(attribute, type = :invalid, message: nil, **options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/interactor/validation/errors.rb', line 16 def add(attribute, type = :invalid, message: nil, **) @errors << Error.new( attribute: attribute, type: type, message: || type.to_s, options: ) # Raise HaltValidation if halt is configured raise HaltValidation if @halt_checker&.call end |
#any? ⇒ Boolean
32 33 34 |
# File 'lib/interactor/validation/errors.rb', line 32 def any? !empty? end |
#clear ⇒ Object
36 37 38 |
# File 'lib/interactor/validation/errors.rb', line 36 def clear @errors.clear end |
#each ⇒ Object
40 41 42 |
# File 'lib/interactor/validation/errors.rb', line 40 def each(&) @errors.each(&) end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/interactor/validation/errors.rb', line 28 def empty? @errors.empty? end |
#to_a ⇒ Object
44 45 46 |
# File 'lib/interactor/validation/errors.rb', line 44 def to_a @errors.dup end |