Class: VisualizeRuby::ExecutionTracer

Inherits:
Object
  • Object
show all
Defined in:
lib/visualize_ruby/execution_tracer.rb

Constant Summary collapse

TRACE_POINT_OPTIONS =
[
    :line
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder = nil, ruby_code: builder.ruby_code, calling_code:, trace_point_options: TRACE_POINT_OPTIONS) ⇒ ExecutionTracer

Returns a new instance of ExecutionTracer.

Parameters:

  • ruby_code (String, File, Pathname) (defaults to: builder.ruby_code)
  • calling_code (File, String, Pathname, Proc)
  • trace_point_options (Array<Symbol>) (defaults to: TRACE_POINT_OPTIONS)


13
14
15
16
17
18
19
# File 'lib/visualize_ruby/execution_tracer.rb', line 13

def initialize(builder = nil, ruby_code: builder.ruby_code, calling_code:, trace_point_options: TRACE_POINT_OPTIONS)
  @ruby_code           = InputCoercer.new(ruby_code, name: :ruby_code).tap(&:to_file)
  @calling_code        = InputCoercer.new(calling_code, name: :calling_code).tap(&:to_proc)
  @trace_point_options = trace_point_options
  @temp_files          = []
  @executed_events     = []
end

Instance Attribute Details

#executed_eventsObject (readonly)

Returns the value of attribute executed_events.



9
10
11
# File 'lib/visualize_ruby/execution_tracer.rb', line 9

def executed_events
  @executed_events
end

Instance Method Details

#traceObject



21
22
23
24
25
26
27
28
# File 'lib/visualize_ruby/execution_tracer.rb', line 21

def trace
  ruby_code.load_file
  tracer.enable(&calling_code.to_proc)
  self
ensure
  ruby_code.close!
  calling_code.close!
end