Class: Brute::Hooks::Trace
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Brute::Hooks::Trace
- 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
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #current_trace ⇒ Object
- #emit(event, *extras, &work) ⇒ Object
- #emit_trace(&block) ⇒ Object
-
#initialize(env, hooks: nil, id: SecureRandom.uuid) ⇒ Trace
constructor
A new instance of Trace.
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
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
53 54 55 |
# File 'lib/brute/hooks.rb', line 53 def hooks @hooks end |
#id ⇒ Object (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_trace ⇒ Object
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__ } |