class Trip::Event

Constants

CallerContext

@attr_reader [Module] module

The module where an event occurred.

@attr_reader [Symbol] method_name

The name of a method where an event occurred.

Attributes

created_at[R]

@return [Integer]

Number of seconds since epoch.
name[R]

Returns one of the following event names:

* c-call
* c-return
* call
* return
* class
* end
* line
* raise

@return [String]

an event name

Public Class Methods

new(name, event) click to toggle source
# File lib/trip/event.rb, line 30
def initialize(name, event)
  @name = name
  @event = event
  @created_at = ::Process.clock_gettime(::Process::CLOCK_REALTIME)
end

Public Instance Methods

__binding__() click to toggle source

@return [Binding]

Returns a binding object for an instance of {Trip::Event}.
# File lib/trip/event.rb, line 131
def __binding__
  ::Kernel.binding
end
binding() click to toggle source

@return [Binding]

Returns a Binding object in the context of where
an event occurred.
# File lib/trip/event.rb, line 58
def binding
  @event[:binding]
end
c_call?() click to toggle source

@return [Boolean]

Returns true when an event is a call to a method
implemented in C.
# File lib/trip/event.rb, line 79
def c_call?
  @name == "c-call"
end
c_return?() click to toggle source

@return [Boolean]

Returns true when an event is a return from a
method implemented in C.
# File lib/trip/event.rb, line 86
def c_return?
  @name == "c-return"
end
call?() click to toggle source

@return [Boolean]

Returns true when an event is a call to a
method implemented in Ruby or C.
# File lib/trip/event.rb, line 93
def call?
  c_call? || rb_call?
end
caller_context() click to toggle source

@return [Trip::Event::CallerContext]

Returns a struct containing the module and method name
where an event occurred.
# File lib/trip/event.rb, line 51
def caller_context
  CallerContext.new @event[:module], @event[:method_name]
end
inspect() click to toggle source

@return [String]

# File lib/trip/event.rb, line 121
def inspect
  "#<Trip::Event:0x#{__id__.to_s(16)} " \
  "name='#{name}'" \
  "file='#{path}' lineno='#{lineno}' " \
  "module='#{caller_context.module}' method_name='#{caller_context.method_name}' " \
  "binding=#{binding.inspect}>"
end
lineno() click to toggle source

@return [Integer]

Returns the line number where an event occurred.
# File lib/trip/event.rb, line 44
def lineno
  @event[:lineno]
end
path() click to toggle source

@return [String]

Returns the path where an event occurred.
# File lib/trip/event.rb, line 38
def path
  @event[:path]
end
rb_call?() click to toggle source

@return [Boolean]

Returns true when an event is a call from a
method implemented in Ruby.
# File lib/trip/event.rb, line 65
def rb_call?
  @name == "call"
end
rb_return?() click to toggle source

@return [Boolean]

Returns true when an event is a return from a
method implemented in Ruby.
# File lib/trip/event.rb, line 72
def rb_return?
  @name == "return"
end
return?() click to toggle source

@return [Boolean]

Returns true when an event is a return from a
method implemented in Ruby or C.
# File lib/trip/event.rb, line 100
def return?
  c_return? || rb_return?
end
signature() click to toggle source

@example

event1.signature  # => "Foo.bar"
event2.signature  # => "Foo#bar"

@return [String]

Returns the signature for the method where an event occurred
by using "#" to denote instance methods and using "." to denote
singleton methods.
# File lib/trip/event.rb, line 112
def signature
  [
    caller_context.module.to_s,
    method_notation,
    caller_context.method_name
  ].join
end

Private Instance Methods

method_notation() click to toggle source

Best guess the method notation to use.

# File lib/trip/event.rb, line 138
def method_notation
  # C method calls and returns have a Binding whose
  # receiver is the self of the nearest Ruby method
  # rather than the self of the C method under trace.
  #
  # As a result we best guess if the method is an instance
  # method or a singleton method for methods implemented in C.
  if c_call? || c_return?
    mod = caller_context.module
    mname = caller_context.method_name
    if ::Module === mod
      if mod.method_defined?(mname) || mod.private_method_defined?(mname)
        "#"
      else
        "."
      end
    else
      "#"
    end
  else
    ::Module === binding.receiver ? "." : "#"
  end
end