Module: RocketPants::ErrorHandling::ClassMethods

Defined in:
lib/rocket_pants/controller/error_handling.rb

Instance Method Summary collapse

Instance Method Details

#map_error!(from, to = nil, &blk) ⇒ Object

Declares that a given error class (e.g. ActiveRecord::RecordNotFound) should map to a second value - either an Exception class Or, more usefully, a callable object.

Parameters:

  • from (Class)

    the exception class to map from.

  • to (Class, #call) (defaults to: nil)

    the callable to map to, or a callback block.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
# File 'lib/rocket_pants/controller/error_handling.rb', line 21

def map_error!(from, to = nil, &blk)
  to = (to || blk)
  raise ArgumentError, "Either an option must be provided or a block given." unless to
  error_mapping[from] = (to || blk)
  rescue_from from, :with => :render_error
end