Class: Cauldron::Tracer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sexp) ⇒ Tracer

Returns a new instance of Tracer.



7
8
9
10
# File 'lib/cauldron/tracer.rb', line 7

def initialize(sexp)
  @sexp = sexp
  @results = []
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



5
6
7
# File 'lib/cauldron/tracer.rb', line 5

def results
  @results
end

#sexpObject (readonly)

Returns the value of attribute sexp.



5
6
7
# File 'lib/cauldron/tracer.rb', line 5

def sexp
  @sexp
end

Class Method Details

.substitue_trackingObject



36
37
38
39
40
# File 'lib/cauldron/tracer.rb', line 36

def self.substitue_tracking
  %q{
  record("line", "depth", "total_lines", "point")
  }
end

.tracking(line, depth, total_line, point) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/cauldron/tracer.rb', line 42

def self.tracking(line, depth, total_line, point)
  a = %Q{
    record(#{line}, #{depth}, #{total_line}, #{point}, local_variables.reject { |foo|
      foo == :_
    }.collect { |bar|
      [bar, eval(bar.to_s)]
    })
  }   
  Ripper::SexpBuilder.new(a).parse
end

Instance Method Details

#process(example) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cauldron/tracer.rb', line 12

def process(example)
  object = Tracer.new(sexp)
  object.instance_eval(Sorcerer.source(sexp, indent: true))
  object.function(example.arguments.first)

  History.new(object.results)
#rescue => e
  # binding.pry
  # Sorcerer.source(sexp, indent: true) 
  # var0 = [5,7]
end

#record(line, depth, total_line, point, entry) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cauldron/tracer.rb', line 24

def record(line, depth, total_line, point, entry)
  #h = Hash[*entry.flatten] 
  h = Hash[*entry.flatten(1)]
  h.merge!(:line => line)
  h.merge!(:depth => depth)
  h.merge!(:total_line => total_line)
  h.merge!(:point => point)
  h = h.reject {|key,value| key.to_s.match /^placeholder/ }
  @results << h
  #@results << #entry # TODO Only want the trace to have on result so it should probably be in the initilaize call only
end