Module: Clepsydra

Defined in:
lib/clepsydra.rb,
lib/clepsydra/version.rb,
lib/clepsydra/notifier.rb,
lib/clepsydra/subscriber.rb,
lib/clepsydra/instrumenter.rb,
lib/clepsydra/token_provider.rb

Defined Under Namespace

Modules: TokenProvider, Version Classes: Instrumenter, InvalidSubscriptionError, Notifier, Subscriber

Class Method Summary collapse

Class Method Details

.finish(event_name, event_id, payload = {}) ⇒ Object



49
50
51
# File 'lib/clepsydra.rb', line 49

def finish(event_name, event_id, payload = {})
  instrumenter.finish(event_name, event_id, payload) if notifier.subscribed?(event_name)
end

.instrument(event_name, payload = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/clepsydra.rb', line 37

def instrument(event_name, payload = {})
  if notifier.subscribed?(event_name)
    instrumenter.instrument(event_name, payload) { yield payload if block_given? }
  elsif block_given?
    yield payload
  end
end

.monotonic_subscribe(event_name, &block) ⇒ Object



23
24
25
26
27
# File 'lib/clepsydra.rb', line 23

def monotonic_subscribe(event_name, &block)
  raise InvalidSubscriptionError, 'No block given' unless block

  notifier.subscribe(event_name, true, &block)
end

.start(event_name) ⇒ Object



45
46
47
# File 'lib/clepsydra.rb', line 45

def start(event_name)
  instrumenter.start(event_name) if notifier.subscribed?(event_name)
end

.subscribe(event_name, &block) ⇒ Object



17
18
19
20
21
# File 'lib/clepsydra.rb', line 17

def subscribe(event_name, &block)
  raise InvalidSubscriptionError, 'No block given' unless block

  notifier.subscribe(event_name, false, &block)
end

.unsubscribe(subscriber) ⇒ Object



33
34
35
# File 'lib/clepsydra.rb', line 33

def unsubscribe(subscriber)
  notifier.unsubscribe(subscriber) if subscriber.is_a?(Clepsydra::Subscriber)
end

.unsubscribe_all(event_name) ⇒ Object



29
30
31
# File 'lib/clepsydra.rb', line 29

def unsubscribe_all(event_name)
  notifier.unsubscribe_all(event_name) if event_name.is_a?(String)
end