Class: Pione::Command::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/command/common.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.



179
180
181
182
# File 'lib/pione/command/common.rb', line 179

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

Instance Method Details

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



193
194
195
# File 'lib/pione/command/common.rb', line 193

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

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



184
185
186
187
188
189
190
191
# File 'lib/pione/command/common.rb', line 184

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