Class: ActiveSupport::Notifications::Service
- Inherits:
-
Object
- Object
- ActiveSupport::Notifications::Service
- Defined in:
- lib/active_support/notifications.rb
Instance Attribute Summary collapse
-
#instrumenter ⇒ Object
readonly
Returns the value of attribute instrumenter.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
Instance Method Summary collapse
-
#initialize(notifier) ⇒ Service
constructor
A new instance of Service.
- #instrument(name, payload = {}) ⇒ Object
- #publish(name, *args) ⇒ Object
- #subscribe(*args, &block) ⇒ Object
- #subscribed(callback, *args) ⇒ Object
- #unsubscribe(args) ⇒ Object
Constructor Details
#initialize(notifier) ⇒ Service
Returns a new instance of Service.
115 116 117 118 119 |
# File 'lib/active_support/notifications.rb', line 115 def initialize(notifier) @notifier = notifier @instrumenter = Instrumenter.new(notifier) @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) } end |
Instance Attribute Details
#instrumenter ⇒ Object (readonly)
Returns the value of attribute instrumenter.
113 114 115 |
# File 'lib/active_support/notifications.rb', line 113 def instrumenter @instrumenter end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
113 114 115 |
# File 'lib/active_support/notifications.rb', line 113 def notifier @notifier end |
Instance Method Details
#instrument(name, payload = {}) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/active_support/notifications.rb', line 125 def instrument(name, payload = {}) if @instrumenters[name] @instrumenter.instrument(name, payload) { yield payload if block_given? } else yield payload if block_given? end end |
#publish(name, *args) ⇒ Object
121 122 123 |
# File 'lib/active_support/notifications.rb', line 121 def publish(name, *args) @notifier.publish(name, *args) end |
#subscribe(*args, &block) ⇒ Object
133 134 135 136 137 |
# File 'lib/active_support/notifications.rb', line 133 def subscribe(*args, &block) @notifier.subscribe(*args, &block).tap do @instrumenters.clear end end |
#subscribed(callback, *args) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/active_support/notifications.rb', line 139 def subscribed(callback, *args) subscriber = subscribe(*args, &callback) yield ensure unsubscribe(subscriber) end |
#unsubscribe(args) ⇒ Object
146 147 148 149 |
# File 'lib/active_support/notifications.rb', line 146 def unsubscribe(args) @notifier.unsubscribe(args) @instrumenters.clear end |