Class: SourceRoute::Wrapper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/source_route/wrapper.rb

Defined Under Namespace

Classes: Condition

Constant Summary collapse

TRACE_POINT_METHODS =
[:defined_class, :method_id, :path, :lineno]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWrapper

Returns a new instance of Wrapper.



52
53
54
# File 'lib/source_route/wrapper.rb', line 52

def initialize
  reset
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



8
9
10
# File 'lib/source_route/wrapper.rb', line 8

def condition
  @condition
end

#output_include_instance_variablesObject

Returns the value of attribute output_include_instance_variables.



9
10
11
# File 'lib/source_route/wrapper.rb', line 9

def output_include_instance_variables
  @output_include_instance_variables
end

#output_include_local_variablesObject

Returns the value of attribute output_include_local_variables.



9
10
11
# File 'lib/source_route/wrapper.rb', line 9

def output_include_local_variables
  @output_include_local_variables
end

#tpObject

Returns the value of attribute tp.



8
9
10
# File 'lib/source_route/wrapper.rb', line 8

def tp
  @tp
end

#tp_attrs_resultsObject

Returns the value of attribute tp_attrs_results.



8
9
10
# File 'lib/source_route/wrapper.rb', line 8

def tp_attrs_results
  @tp_attrs_results
end

Instance Method Details

#resetObject

output_format can be console, html



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/source_route/wrapper.rb', line 57

def reset
  @tp.disable if @tp
  @condition = Condition.new([:call], {}, {},
                             { output_format: 'none',
                               selected_attrs: nil,
                               include_local_var: false,
                               include_instance_var: false
                             })
  @tp_attrs_results = []
  self
end

#traceObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/source_route/wrapper.rb', line 70

def trace
  # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace
  tp_result = TpResult.new(self)

  track = TracePoint.new *condition.events do |tp|
    # todo: it's better to change the break check to condition methods to make more flexible
    negative_break = condition.negative.any? do |method_key, value|
      tp.send(method_key).to_s =~ Regexp.new(value)
    end
    next if negative_break

    positive_break = condition.positive.any? do |method_key, value|
      tp.send(method_key).to_s !~ Regexp.new(value)
    end
    next if positive_break

    unless condition[:result_config][:output_format].is_a? Proc
      ret_data = tp_result.build(tp)
      tp_attrs_results.push(ret_data)
    end

    tp_result.output(tp)
  end
  track.enable
  self.tp = track
  track
end