Class: CallGraph::Instrument

Inherits:
Object
  • Object
show all
Defined in:
lib/call_graph/instrument.rb

Constant Summary collapse

INTROSPECT =
"(self.class == Class ? self.name : self.class.name) + ' ' + (self.class == Class ? '(Class)' : '(Instance)') rescue binding.source_location.first"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path: default_file_path) ⇒ Instrument

Returns a new instance of Instrument.



10
11
12
13
# File 'lib/call_graph/instrument.rb', line 10

def initialize(file_path: default_file_path)
  @file_path      = file_path
  @set            = Set.new
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



8
9
10
# File 'lib/call_graph/instrument.rb', line 8

def file_path
  @file_path
end

#setObject

Returns the value of attribute set.



8
9
10
# File 'lib/call_graph/instrument.rb', line 8

def set
  @set
end

Instance Method Details

#path(kind) ⇒ Object



15
16
17
# File 'lib/call_graph/instrument.rb', line 15

def path(kind)
  "#{file_path}.#{kind}"
end

#trace(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/call_graph/instrument.rb', line 19

def trace(&block)
  trace_point.enable
  yield
  trace_point.disable

  File.open(path(:tmp), 'w') { |fd| fd.write set.to_a.compact.join("\n") }

  set.clear
end