Class: SourceRoute::Wrapper

Inherits:
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.



66
67
68
# File 'lib/source_route/wrapper.rb', line 66

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

#result_builderObject

Returns the value of attribute result_builder.



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

def result_builder
  @result_builder
end

#tpObject

Returns the value of attribute tp.



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

def tp
  @tp
end

Instance Method Details

#resetObject



70
71
72
73
74
75
76
# File 'lib/source_route/wrapper.rb', line 70

def reset
  @tp.disable if defined? @tp
  @condition = Condition.new
  @result_builder = GenerateResult.new(self)
  GenerateResult.clear_wanted_attributes
  self
end

#tp_result_chainObject



107
108
109
# File 'lib/source_route/wrapper.rb', line 107

def tp_result_chain
  result_builder.tp_result_chain
end

#traceObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/source_route/wrapper.rb', line 78

def trace
  # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace

  tp_filter = TpFilter.new(condition)

  track = TracePoint.new *condition.events do |tp|

    next if tp_filter.block_it?(tp)

    # immediate output trace point result
    # here is confused. todo
    # should move tp_result_chain to result generator
    @result_builder.output(tp)
    # if condition.result_config.format == :console
    #   ret_data = build_result.build(tp)
    #   @tp_result_chain.push(ret_data)
    #   build_result.output(tp)
    # elsif condition.result_config.format.is_a? Proc
    #   build_result.output(tp)
    # else
    #   # why not push the tp to result chain
    #   ret_data = build_result.build(tp)
    #   @tp_result_chain.push(ret_data)
    # end
  end
  track.enable
  self.tp = track
end