Class: Orthoses::CallTracer::Lazy

Inherits:
Object
  • Object
show all
Includes:
Capturable
Defined in:
lib/orthoses/call_tracer/lazy.rb

Overview

CallTracer::Lazy is possible to perform a trace equivalent to CallTracer before method is defined.

scope = CallTracerLazy.new
scope.trace("ActiveRecord::Base#scope") do
  require 'active_record/all'
  @loader.call
end
scope.captures.each do |capture|
  capture.argument[:name]
  capture.argument[:body]
  capture.argument[:block]
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Capturable

#build_capture

Constructor Details

#initializeLazy

Returns a new instance of Lazy.



22
23
24
25
26
27
# File 'lib/orthoses/call_tracer/lazy.rb', line 22

def initialize
  @captures = []
  @lazy_trace_point = LazyTracePoint.new(:call) do |tp|
    @captures << build_capture(tp)
  end
end

Instance Attribute Details

#capturesObject (readonly)

Returns the value of attribute captures.



20
21
22
# File 'lib/orthoses/call_tracer/lazy.rb', line 20

def captures
  @captures
end

Instance Method Details

#trace(name, &block) ⇒ Object



29
30
31
# File 'lib/orthoses/call_tracer/lazy.rb', line 29

def trace(name, &block)
  @lazy_trace_point.enable(target: name, &block)
end