Class: David::Observe

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Actor
Defined in:
lib/david/observe.rb

Instance Method Summary collapse

Methods included from Actor

included

Constructor Details

#initialize(tick_interval = 3) ⇒ Observe

Returns a new instance of Observe.


9
10
11
12
13
14
15
16
# File 'lib/david/observe.rb', line 9

def initialize(tick_interval = 3)
  @tick_interval = tick_interval
  @store = {}

  async.run

  log.debug('Observe initialized')
end

Instance Method Details

#add(exchange, env, etag) ⇒ Object


18
19
20
21
22
23
# File 'lib/david/observe.rb', line 18

def add(exchange, env, etag)
  exchange.message.options.delete(:observe)

  @store[[exchange.host, exchange.token]] ||=
    [0, exchange, env, etag, Time.now.to_i]
end

#delete(exchange) ⇒ Object


25
26
27
# File 'lib/david/observe.rb', line 25

def delete(exchange)
  @store.delete([exchange.host, exchange.token])
end

#get(key) ⇒ Object


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

def get(key)
  @store[key]
end

#include?(exchange) ⇒ Boolean

Returns:

  • (Boolean)

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

def include?(exchange)
  @store.include?([exchange.host, exchange.token])
end

#to_sObject


37
38
39
# File 'lib/david/observe.rb', line 37

def to_s
  @store.map { |k, v| [*k, v[2]['PATH_INFO'], v[0]].inspect }.join(', ')
end