Class: Tavern::History::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tavern/history/base.rb

Direct Known Subclasses

Redis

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hub) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/tavern/history/base.rb', line 7

def initialize(hub)
  @hub = hub
  hub.subscribe('') { |event| persist event }
end

Instance Attribute Details

#hubObject (readonly)

Returns the value of attribute hub.



5
6
7
# File 'lib/tavern/history/base.rb', line 5

def hub
  @hub
end

Instance Method Details

#history(channel, limit = 10) ⇒ Object



12
13
14
15
# File 'lib/tavern/history/base.rb', line 12

def history(channel, limit = 10)
  identifiers = identifiers_for channel, limit
  fetch identifiers
end

#persist(event) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/tavern/history/base.rb', line 17

def persist(event)
  identifier = record event
  each_subchannel event do |channel|
    add_record channel, identifier
  end
  true
end

#publish(*args, &blk) ⇒ Object



27
# File 'lib/tavern/history/base.rb', line 27

def publish(*args, &blk);     hub.publish(*args, &blk);     end

#subscribe(*args, &blk) ⇒ Object



25
# File 'lib/tavern/history/base.rb', line 25

def subscribe(*args, &blk);   hub.subscribe(*args, &blk);   end

#unsubscribe(*args, &blk) ⇒ Object



26
# File 'lib/tavern/history/base.rb', line 26

def unsubscribe(*args, &blk); hub.unsubscribe(*args, &blk); end