Class: Brute::Hooks::Trace

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/brute/hooks.rb

Overview

The env, wrapped, for as long as one call lasts. Everything emitted through it carries that call's id, and a call opened inside another delegates to it -- so the wrapper is the parent and unwrapping ends the call. It is still the env: SimpleDelegator forwards the rest.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, hooks: nil, id: SecureRandom.uuid) ⇒ Trace

Returns a new instance of Trace.



55
56
57
58
59
60
61
62
63
# File 'lib/brute/hooks.rb', line 55

def initialize(env, hooks: nil, id: SecureRandom.uuid)
  super(env)
  if hooks
    @hooks = hooks
  elsif env.is_a?(Trace)
    @hooks = env.hooks
  end
  @id = id
end

Instance Attribute Details

#hooksObject (readonly)

Returns the value of attribute hooks.



53
54
55
# File 'lib/brute/hooks.rb', line 53

def hooks
  @hooks
end

#idObject (readonly)

Returns the value of attribute id.



53
54
55
# File 'lib/brute/hooks.rb', line 53

def id
  @id
end

Instance Method Details

#current_traceObject



65
# File 'lib/brute/hooks.rb', line 65

def current_trace = self

#emit(event, *extras, &work) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/brute/hooks.rb', line 67

def emit(event, *extras, &work) = @hooks.emit(
  event,
  self,
  *extras,
  @id,
  &work
)

#emit_trace(&block) ⇒ Object



75
# File 'lib/brute/hooks.rb', line 75

def emit_trace(&block) = self.class.new(self).tap(&block).then { |trace| trace.__getobj__ }