Module: Bidi2pdf::Notifications
- Defined in:
- lib/bidi2pdf/notifications.rb,
lib/bidi2pdf/notifications/event.rb,
lib/bidi2pdf/notifications/instrumenter.rb,
lib/bidi2pdf/notifications/logging_subscriber.rb
Overview
rubocop: disable Lint/RescueException, Lint/SuppressedException
Defined Under Namespace
Modules: LoggingSubscriberActions Classes: Event, Instrumenter, LoggingSubscriber
Class Attribute Summary collapse
-
.subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Instance Attribute Summary collapse
-
#bidi2pdf_notification_instrumenter ⇒ Object
Returns the value of attribute bidi2pdf_notification_instrumenter.
Class Method Summary collapse
- .instrument(name, payload = {}) ⇒ Object
-
.listening?(name) ⇒ Boolean
rubocop: disable Style/CaseEquality.
- .subscribe(event_pattern, &block) ⇒ Object
- .unsubscribe(event_pattern, block = nil) ⇒ Object
Class Attribute Details
.subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
24 25 26 |
# File 'lib/bidi2pdf/notifications.rb', line 24 def subscribers @subscribers end |
Instance Attribute Details
#bidi2pdf_notification_instrumenter ⇒ Object
Returns the value of attribute bidi2pdf_notification_instrumenter.
19 20 21 |
# File 'lib/bidi2pdf/notifications.rb', line 19 def bidi2pdf_notification_instrumenter @bidi2pdf_notification_instrumenter end |
Class Method Details
.instrument(name, payload = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/bidi2pdf/notifications.rb', line 26 def instrument(name, payload = {}) payload = payload.dup if listening?(name) notify(name, payload) { yield payload if block_given? } elsif block_given? yield payload end end |
.listening?(name) ⇒ Boolean
rubocop: disable Style/CaseEquality
55 56 57 58 59 |
# File 'lib/bidi2pdf/notifications.rb', line 55 def listening?(name) @subscribers.any? do |pattern, blocks| pattern === name && blocks.any? end end |
.subscribe(event_pattern, &block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/bidi2pdf/notifications.rb', line 36 def subscribe(event_pattern, &block) pattern = normalize_pattern(event_pattern) @subscribers[pattern] << block block end |
.unsubscribe(event_pattern, block = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/bidi2pdf/notifications.rb', line 44 def unsubscribe(event_pattern, block = nil) pattern = normalize_pattern(event_pattern) if block @subscribers[pattern].delete(block) else @subscribers[pattern].clear end end |