Class: Derketo::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/derketo/tracer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope: nil) ⇒ Tracer

Returns a new instance of Tracer.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/derketo/tracer.rb', line 7

def initialize(scope: nil)
  @events = Derketo::EventTrace.new
  @tracepoint = TracePoint.new(:call, :return) do |tp|
    if scope.nil? || tp.path.include?(scope)
      if tp.event == :call
        @events.push(Derketo::Events::Call.new(tp))
      elsif tp.event == :return
        @events.push(Derketo::Events::Return.new(tp))
      end
    end
  end
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



6
7
8
# File 'lib/derketo/tracer.rb', line 6

def events
  @events
end

Instance Method Details

#traceObject



20
21
22
23
24
25
# File 'lib/derketo/tracer.rb', line 20

def trace
  @tracepoint.enable
  response = yield
  @tracepoint.disable
  response
end