Class: Meerkat::Backend::InMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/meerkat/backend/inmemory.rb

Instance Method Summary collapse

Constructor Details

#initializeInMemory

Returns a new instance of InMemory.



6
7
8
# File 'lib/meerkat/backend/inmemory.rb', line 6

def initialize
  @channel = EventMachine::Channel.new
end

Instance Method Details

#publish(topic, json) ⇒ Object



10
11
12
# File 'lib/meerkat/backend/inmemory.rb', line 10

def publish(topic, json)
  @channel.push({:topic => topic, :json => json})
end

#subscribe(topic, &callback) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/meerkat/backend/inmemory.rb', line 14

def subscribe(topic, &callback)
  @channel.subscribe do |msg|
    if File.fnmatch? topic, msg[:topic]
      callback.call msg[:topic], msg[:json]
    end
  end
end

#unsubscribe(sid) ⇒ Object



22
23
24
# File 'lib/meerkat/backend/inmemory.rb', line 22

def unsubscribe(sid)
  @channel.unsubscribe(sid)
end