Module: Juggernaut
- Extended by:
- Juggernaut
- Included in:
- Juggernaut
- Defined in:
- lib/juggernaut.rb,
lib/juggernaut/rails/engine.rb
Constant Summary collapse
- EVENTS =
[ "juggernaut:subscribe", "juggernaut:unsubscribe", "juggernaut:custom" ]
Instance Method Summary collapse
- #options ⇒ Object
- #options=(val) ⇒ Object
- #publish(channels, data, options = {}) ⇒ Object
- #subscribe ⇒ Object
- #url=(url) ⇒ Object
Instance Method Details
#options ⇒ Object
14 15 16 |
# File 'lib/juggernaut.rb', line 14 def @options ||= {} end |
#options=(val) ⇒ Object
18 19 20 |
# File 'lib/juggernaut.rb', line 18 def (val) @options = val end |
#publish(channels, data, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/juggernaut.rb', line 26 def publish(channels, data, = {}) = ({:channels => Array(channels).uniq, :data => data}).merge() redis.publish(key, .to_json) end |
#subscribe ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/juggernaut.rb', line 31 def subscribe Redis.connect().subscribe(*EVENTS) do |on| on. do |type, msg| yield(type.gsub(/^juggernaut:/, "").to_sym, JSON.parse(msg)) end end end |
#url=(url) ⇒ Object
22 23 24 |
# File 'lib/juggernaut.rb', line 22 def url=(url) [:url] = url end |