class Kojak::Caller

Internal: Caller wraps a method with inspection mechanism.

Public Class Methods

new(method) click to toggle source

Public: Constructor. Wraps given method with caller. Gathers initial information about this call.

method - The Method to be wrapped.

Returns nothing.

# File lib/kojak/caller.rb, line 10
def initialize(method)
  @method = method

  replace({
    :name      => "#{method.owner.name}##{method.name}",
    :method    => method,
    :location  => method.source_location,
    :pid       => Process.pid,
    :thread    => Thread.current,
    :thread_id => Thread.object_id,
  })
end

Public Instance Methods

call(*args, &block) click to toggle source

Public: Calls wrapped method with given arguments and block, and collects all information about this particular call.

args - The Array with arguments to pass. block - The Proc with block to pass.

Returns stuff returned by called method. Raises exceptions by called method if any.

# File lib/kojak/caller.rb, line 31
def call(*args, &block)
  merge!({
    :block_given => block_given?,
    :block       => block,
    :args        => args
  })

  res, err = nil, nil
  rt = Benchmark.realtime do
    begin
      res = @method.call(*args, &block)
    rescue Exception => e
      err = e
    end
  end

  merge!({
    :receiver => @method.receiver.class.name,
    :realtime => rt,
    :result   => res,
    :err      => err
  })

  raise err if err
  res
end