Exception: MuchRails::InvalidError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/much-rails/invalid_error.rb

Overview

MuchRails::InvalidError allows for raising and auto-rescueing general validation errors outside the scope of e.g. an ActiveRecord save.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backtrace: nil, **errors) ⇒ InvalidError

Returns a new instance of InvalidError.



10
11
12
13
14
15
# File 'lib/much-rails/invalid_error.rb', line 10

def initialize(backtrace: nil, **errors)
  @errors = errors

  super(@errors.inspect)
  set_backtrace(backtrace) if backtrace
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/much-rails/invalid_error.rb', line 8

def errors
  @errors
end

Instance Method Details

#error_messagesObject



17
18
19
20
21
# File 'lib/much-rails/invalid_error.rb', line 17

def error_messages
  @errors.to_a.map do |(field_name, message)|
    "#{field_name}: #{Array.wrap(message).to_sentence}"
  end
end