Class: ActionInteractor::Errors
- Inherits:
-
Object
- Object
- ActionInteractor::Errors
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/action_interactor/errors.rb
Overview
Action Interactor Errors
Provides a Hash
like object to Action Interactors execution errors.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#add(attribute, error) ⇒ Object
Add
error
to the errors hash. -
#delete(key) ⇒ Object
Delete a error for
key
. -
#each ⇒ Object
Iterates through each error key, value pair in the errors hash.
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
-
#messages ⇒ Object
Returns array containing error messages.
-
#to_hash ⇒ Object
Convert errors to hash.
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
16 17 18 |
# File 'lib/action_interactor/errors.rb', line 16 def initialize(*) @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
12 13 14 |
# File 'lib/action_interactor/errors.rb', line 12 def errors @errors end |
Instance Method Details
#add(attribute, error) ⇒ Object
Add error
to the errors hash.
21 22 23 |
# File 'lib/action_interactor/errors.rb', line 21 def add(attribute, error) errors[attribute.to_sym] = error end |
#delete(key) ⇒ Object
Delete a error for key
.
26 27 28 29 |
# File 'lib/action_interactor/errors.rb', line 26 def delete(key) attribute = key.to_sym errors.delete(attribute) end |
#each ⇒ Object
Iterates through each error key, value pair in the errors hash.
32 33 34 35 36 |
# File 'lib/action_interactor/errors.rb', line 32 def each errors.each_key do |attribute| yield attribute, errors[attribute] end end |
#messages ⇒ Object
Returns array containing error messages.
44 45 46 47 48 |
# File 'lib/action_interactor/errors.rb', line 44 def errors.map do |attribute, error| "#{attribute} #{error}" end end |
#to_hash ⇒ Object
Convert errors to hash.
39 40 41 |
# File 'lib/action_interactor/errors.rb', line 39 def to_hash errors end |