Class: RShade::TraceObservable

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/rshade/trace_observable.rb

Constant Summary collapse

CALL_EVENTS =
Set[:call, :c_call, :b_call]
RETURN_EVENTS =
Set[:return, :c_return, :b_return]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(observers, config) ⇒ TraceObservable

Returns a new instance of TraceObservable.

Parameters:



10
11
12
13
14
15
16
17
# File 'lib/rshade/trace_observable.rb', line 10

def initialize(observers, config)
  @trace_p = TracePoint.new(*config.tp_events, &method(:process))
  observers = [observers] unless observers.is_a?(Enumerable)

  observers.each do |observer|
    add_observer(observer, :call)
  end
end

Instance Attribute Details

#trace_pObject (readonly)

Returns the value of attribute trace_p.



4
5
6
# File 'lib/rshade/trace_observable.rb', line 4

def trace_p
  @trace_p
end

Instance Method Details

#revealObject



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

def reveal
  return unless block_given?

  trace_p.enable
  yield
  self
ensure
  trace_p.disable
end