Class: Tavern::Redis::Hub

Inherits:
Hub
  • Object
show all
Defined in:
lib/tavern/redis/hub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis = Redis.current) ⇒ Hub

Returns a new instance of Hub.



9
10
11
12
# File 'lib/tavern/redis/hub.rb', line 9

def initialize(redis = Redis.current)
  @redis = redis
  super()
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



7
8
9
# File 'lib/tavern/redis/hub.rb', line 7

def redis
  @redis
end

Instance Method Details

#local_publishObject



14
# File 'lib/tavern/redis/hub.rb', line 14

alias local_publish publish

#publish(name, context = {}) ⇒ Object

Now, provide our own local publish.



17
18
19
# File 'lib/tavern/redis/hub.rb', line 17

def publish(name, context = {})
  redis.publish "event:#{name}", MultiJson.dump(context)
end

#startObject



21
22
23
24
25
26
27
28
# File 'lib/tavern/redis/hub.rb', line 21

def start
  redis.psubscribe "event:*" do |on|
    on.pmessage do |_, channel, message|
      receive_json channel, message
    end
  end

end