Module: AdequateErrors::Interceptor

Defined in:
lib/adequate_errors/interceptor.rb

Overview

Wraps around Rails’ errors object, intercepting its state changes in order to update AdequateErrors’ errors object.

Instance Method Summary collapse

Instance Method Details

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/adequate_errors/interceptor.rb', line 24

def add(attribute, message = :invalid, options = {})
  adequate_options = options.dup

  messages = super

  if options.has_key?(:message) && !options[:message].is_a?(Symbol)
    adequate_options[:message] = full_message(attribute, messages.last)
  end

  adequate_message = if !message.is_a?(Symbol)
    full_message(attribute, messages.last)
  else
    message
  end

  @adequate_errors.add(attribute, adequate_message, adequate_options)
end

#adequateObject

Accessor



43
44
45
# File 'lib/adequate_errors/interceptor.rb', line 43

def adequate
  @adequate_errors
end

#clearObject



14
15
16
17
# File 'lib/adequate_errors/interceptor.rb', line 14

def clear
  super
  @adequate_errors.clear
end

#delete(key) ⇒ Object



19
20
21
22
# File 'lib/adequate_errors/interceptor.rb', line 19

def delete(key)
  super
  @adequate_errors.delete(key)
end

#initialize(base) ⇒ Object



8
9
10
11
12
# File 'lib/adequate_errors/interceptor.rb', line 8

def initialize(base)
  rails_errors = super
  @adequate_errors = ::AdequateErrors::Errors.new(base)
  rails_errors
end