Class: Rootage::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rootage/core.rb

Overview

ExceptionHandler is a handler of exception for action item.

Instance Method Summary collapse

Constructor Details

#initialize(exceptions, block) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



463
464
465
466
# File 'lib/rootage/core.rb', line 463

def initialize(exceptions, block)
  @exceptions = exceptions
  @block = block
end

Instance Method Details

#handle(context, e, *args) ⇒ Object



477
478
479
# File 'lib/rootage/core.rb', line 477

def handle(context, e, *args)
  context.instance_exec(e, *args, &@block)
end

#try_to_handle(context, e, *args) ⇒ Object



468
469
470
471
472
473
474
475
# File 'lib/rootage/core.rb', line 468

def try_to_handle(context, e, *args)
  if @exceptions.any?{|ec| e.kind_of?(ec)}
    handle(context, e, *args)
    return true
  end

  return false
end