Class: Trestle::DebugErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/debug_errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ DebugErrors

Returns a new instance of DebugErrors.



3
4
5
# File 'lib/trestle/debug_errors.rb', line 3

def initialize(errors)
  @errors = errors
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/trestle/debug_errors.rb', line 7

def any?
  @errors.any?
end

#eachObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/trestle/debug_errors.rb', line 11

def each
  if defined?(ActiveModel::Error)
    # Rails 6.1 introduces a unified Error class
    @errors.each do |error|
      yield error.attribute, error.message
    end
  else
    @errors.each do |error, message|
      yield error, message
    end
  end
end