Sha256: 96818d379af66198a6fc2dc82c94e6c124ca440f198ffbaae0fc39690a278a95
Contents?: true
Size: 737 Bytes
Versions: 2
Compression:
Stored size: 737 Bytes
Contents
module Attention # Uses Redis pub/sub to publish events class Publisher # 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 def publish(channel, value) redis = Attention.redis.call redis.publish channel, payload_for(value) yield redis if block_given? end # Converts published values to JSON if possible # @api private def payload_for(value) case value when Array, Hash JSON.dump value else value end rescue value end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
attention-0.0.3 | lib/attention/publisher.rb |
attention-0.0.2 | lib/attention/publisher.rb |