Class: ActionInteractor::Errors

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



16
17
18
# File 'lib/action_interactor/errors.rb', line 16

def initialize(*)
  @errors = {}
end

Instance Attribute Details

#errorsObject (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

#eachObject

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

#messagesObject

Returns array containing error messages.



44
45
46
47
48
# File 'lib/action_interactor/errors.rb', line 44

def messages
  errors.map do |attribute, error|
    "#{attribute} #{error}"
  end
end

#to_hashObject

Convert errors to hash.



39
40
41
# File 'lib/action_interactor/errors.rb', line 39

def to_hash
  errors
end