Class: Dry::Monitor::Notifications
- Inherits:
-
Object
- Object
- Dry::Monitor::Notifications
- Includes:
- Core::Constants
- Defined in:
- lib/dry/monitor/notifications.rb
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(id, clock: CLOCK) ⇒ Notifications
constructor
A new instance of Notifications.
- #instrument(event_id, payload = EMPTY_HASH, &block) ⇒ Object
- #start(event_id, payload) ⇒ Object
- #stop(event_id, payload) ⇒ Object
Constructor Details
#initialize(id, clock: CLOCK) ⇒ Notifications
Returns a new instance of Notifications.
15 16 17 18 |
# File 'lib/dry/monitor/notifications.rb', line 15 def initialize(id, clock: CLOCK) @id = id @clock = clock end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
13 14 15 |
# File 'lib/dry/monitor/notifications.rb', line 13 def clock @clock end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/dry/monitor/notifications.rb', line 13 def id @id end |
Instance Method Details
#instrument(event_id, payload = EMPTY_HASH, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dry/monitor/notifications.rb', line 28 def instrument(event_id, payload = EMPTY_HASH, &block) result, time = @clock.measure(&block) if block_given? process(event_id, payload) do |event, listener| if time listener.(event.payload(payload.merge(time: time))) else listener.(event) end end result end |
#start(event_id, payload) ⇒ Object
20 21 22 |
# File 'lib/dry/monitor/notifications.rb', line 20 def start(event_id, payload) instrument(event_id, payload) end |
#stop(event_id, payload) ⇒ Object
24 25 26 |
# File 'lib/dry/monitor/notifications.rb', line 24 def stop(event_id, payload) instrument(event_id, payload) end |