Sha256: aa7f3ccc9aecebab17d7e127e9e013a72aeaf73e51eb2f12d87860eef00cd731
Contents?: true
Size: 737 Bytes
Versions: 3
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 yield redis if block_given? redis.publish channel, payload_for(value) 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
attention-0.0.6 | lib/attention/publisher.rb |
attention-0.0.5 | lib/attention/publisher.rb |
attention-0.0.4 | lib/attention/publisher.rb |