Class: Yoda::Instrument
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/yoda/instrument.rb
Defined Under Namespace
Classes: Progress, Subscription
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Instrument.
86
87
88
|
# File 'lib/yoda/instrument.rb', line 86
def initialize
@subscriptions = []
end
|
Instance Attribute Details
61
62
63
|
# File 'lib/yoda/instrument.rb', line 61
def subscriptions
@subscriptions
end
|
Class Method Details
.clean ⇒ Object
74
75
76
|
# File 'lib/yoda/instrument.rb', line 74
def clean
local.value = Instrument.new
end
|
Returns Instrument instance (thread local).
70
71
72
|
# File 'lib/yoda/instrument.rb', line 70
def instance
local.value
end
|
Instance Method Details
#build_library_registry(message:, name:, version:) ⇒ Object
137
138
139
|
# File 'lib/yoda/instrument.rb', line 137
def build_library_registry(message:, name:, version:)
emit(:build_library_registry, name: name, version: version, message: message)
end
|
#emit(name, **params) ⇒ Object
108
109
110
111
|
# File 'lib/yoda/instrument.rb', line 108
def emit(name, **params)
Logger.trace("#{name}: #{params}")
subscriptions.select { |subscription| subscription.name === name }.each { |subscription| subscription.call(**params) }
end
|
#hear(subscription_hash = {}) ⇒ Object
Add subscriptions and eval the given block. these subscriptions are unsubscribed after the block.
92
93
94
95
96
97
|
# File 'lib/yoda/instrument.rb', line 92
def hear(subscription_hash = {})
subscriptions = subscription_hash.map { |key, value| subscribe(key, &value) }
value = yield
subscriptions.each(&:unsubscribe)
value
end
|
#initialization_progress(phase:, message:, index: nil, length: nil) ⇒ Object
124
125
126
|
# File 'lib/yoda/instrument.rb', line 124
def initialization_progress(phase:, message:, index: nil, length: nil)
emit(:initialization_progress, phase: phase, message: message, index: index, length: length)
end
|
#registry_dump(index: nil, length: nil) ⇒ Object
130
131
132
|
# File 'lib/yoda/instrument.rb', line 130
def registry_dump(index: nil, length: nil)
emit(:registry_dump, index: index, length: length)
end
|
#subscribe(name, &callback) ⇒ Subsctiption
102
103
104
|
# File 'lib/yoda/instrument.rb', line 102
def subscribe(name, &callback)
Subscription.new(instrument: self, name: name, callback: callback).tap { |subscription| subscriptions.push(subscription) }
end
|
#unsubscribe(subscription) ⇒ Object
114
115
116
|
# File 'lib/yoda/instrument.rb', line 114
def unsubscribe(subscription)
subscriptions.delete(subscription)
end
|