Class: ServiceOperation::Errors

Inherits:
Hash
  • Object
show all
Defined in:
lib/service_operation/errors.rb

Overview

Error object with minimal compatibility with ActiveModel style errors

Instance Method Summary collapse

Instance Method Details

#add(attr, *args) ⇒ Object

Examples:

add(:attr, 'error1', 'error2')

Parameters:

  • attr (Symbol)

    to add error to



9
10
11
12
13
14
15
16
# File 'lib/service_operation/errors.rb', line 9

def add(attr, *args)
  return self if args.empty?

  self[attr] ||= []
  self[attr] += args.flatten

  self
end

#coerced_merge(error_hash) ⇒ Object

Parameters:

  • error_hash

    pass any type of error and it will be normalized to { attr: [‘error’] }



19
20
21
22
23
24
25
# File 'lib/service_operation/errors.rb', line 19

def coerced_merge(error_hash)
  ensure_error_hash(error_hash).each do |key, error|
    object_to_array(error).each { |errors| add(key, *errors) }
  end

  self
end