class Attention::Publisher

Uses Redis pub/sub to publish events

Public Instance Methods

payload_for(value) click to toggle source

Converts published values to JSON if possible @api private

# File lib/attention/publisher.rb, line 17
def payload_for(value)
  case value
  when Array, Hash
    JSON.dump value
  else
    value
  end
rescue
  value
end
publish(channel, value) { |redis| ... } click to toggle source

Publishes the value to the channel @param channel [String] The channel to publish to @param value [Object] The value to publish @yield Allows an optional block to use the Redis connection @yieldparam redis [Redis] The Redis connection

# File lib/attention/publisher.rb, line 9
def publish(channel, value)
  redis = Attention.redis.call
  yield redis if block_given?
  redis.publish channel, payload_for(value)
end