Module: ActiveInteraction::Errors::Details

Extended by:
ActiveSupport::Concern
Included in:
ActiveInteraction::Errors
Defined in:
lib/active_interaction/backports.rb

Overview

Required for Rails < 5.

Extracted from active_model-errors_details 1.2.0. Modified to add support for ActiveModel 3.2.0.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#add_with_details(attribute, message = :invalid, options = {}) ⇒ Object

Since:

  • 1.0.0



38
39
40
41
42
43
44
45
# File 'lib/active_interaction/backports.rb', line 38

def add_with_details(attribute, message = :invalid, options = {})
  message = message.call if message.respond_to?(:call)

  error = options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS)
    .merge(error: message)
  details[attribute].push(error)
  add_without_details(attribute, message, options)
end

#clear_with_detailsObject

Since:

  • 1.0.0



47
48
49
50
# File 'lib/active_interaction/backports.rb', line 47

def clear_with_details
  details.clear
  clear_without_details
end

#delete_with_details(attribute) ⇒ Object

Since:

  • 1.0.0



52
53
54
55
# File 'lib/active_interaction/backports.rb', line 52

def delete_with_details(attribute)
  details.delete(attribute)
  delete_without_details(attribute)
end

#initialize_dup_with_details(other) ⇒ Object

Since:

  • 1.0.0



33
34
35
36
# File 'lib/active_interaction/backports.rb', line 33

def initialize_dup_with_details(other)
  @details = other.details.deep_dup
  initialize_dup_without_details(other)
end

#initialize_with_details(base) ⇒ Object

Since:

  • 1.0.0



28
29
30
31
# File 'lib/active_interaction/backports.rb', line 28

def initialize_with_details(base)
  @details = Hash.new { |details, attribute| details[attribute] = [] }
  initialize_without_details(base)
end