Class: MockSuey::Tracer

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

Defined Under Namespace

Classes: PrependCollector, TracePointCollector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(via: :prepend) ⇒ Tracer

Returns a new instance of Tracer.



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mock_suey/tracer.rb', line 124

def initialize(via: :prepend)
  @store = []
  @targets = Hash.new { |h, k| h[k] = [] }
  @collector =
    if via == :prepend
      PrependCollector.new(self)
    elsif via == :trace_point
      TracePointCollector.new(self)
    else
      raise ArgumentError, "Unknown tracing method: #{via}"
    end
end

Instance Attribute Details

#collectorObject (readonly)

Returns the value of attribute collector.



122
123
124
# File 'lib/mock_suey/tracer.rb', line 122

def collector
  @collector
end

#storeObject (readonly)

Returns the value of attribute store.



122
123
124
# File 'lib/mock_suey/tracer.rb', line 122

def store
  @store
end

#targetsObject (readonly)

Returns the value of attribute targets.



122
123
124
# File 'lib/mock_suey/tracer.rb', line 122

def targets
  @targets
end

Instance Method Details

#<<(call_obj) ⇒ Object



154
155
156
# File 'lib/mock_suey/tracer.rb', line 154

def <<(call_obj)
  store << call_obj
end

#collect(klass, methods) ⇒ Object



137
138
139
140
# File 'lib/mock_suey/tracer.rb', line 137

def collect(klass, methods)
  targets[klass].concat(methods)
  targets[klass].uniq!
end

#start!Object



142
143
144
# File 'lib/mock_suey/tracer.rb', line 142

def start!
  collector.setup(targets)
end

#stopObject



146
147
148
149
150
151
152
# File 'lib/mock_suey/tracer.rb', line 146

def stop
  collector.stop
  total = store.size
  filter_calls!
  MockSuey.logger.debug "Collected #{store.size} real calls (#{total - store.size} were filtered)"
  store
end