Class: Sinapse::Channels
- Inherits:
-
Struct
- Object
- Struct
- Sinapse::Channels
- Defined in:
- lib/sinapse/channels.rb
Overview
TODO: #access_token to return the current user token (or generate one if missing)
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #add_channel(channel) ⇒ Object
- #auth ⇒ Object
- #channel_for(record) ⇒ Object
- #channels ⇒ Object
-
#clear ⇒ Object
Removes all channels at once.
-
#destroy ⇒ Object
Removes all channels and clears authentication.
- #has_channel?(channel) ⇒ Boolean
- #key(extra = nil) ⇒ Object
- #remove_channel(channel) ⇒ Object
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record
3 4 5 |
# File 'lib/sinapse/channels.rb', line 3 def record @record end |
Instance Method Details
#add_channel(channel) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/sinapse/channels.rb', line 16 def add_channel(channel) Sinapse.redis do |redis| redis.sadd(key, channel_for(channel)) redis.publish(key(:add), channel_for(channel)) end end |
#auth ⇒ Object
4 5 6 |
# File 'lib/sinapse/channels.rb', line 4 def auth @auth ||= Authentication.new(record) end |
#channel_for(record) ⇒ Object
41 42 43 |
# File 'lib/sinapse/channels.rb', line 41 def channel_for(record) record.is_a?(String) ? record : record.sinapse_channel end |
#channels ⇒ Object
8 9 10 |
# File 'lib/sinapse/channels.rb', line 8 def channels Sinapse.redis { |redis| redis.smembers(key) } end |
#clear ⇒ Object
Removes all channels at once.
31 32 33 |
# File 'lib/sinapse/channels.rb', line 31 def clear channels.each { |channel| remove_channel(channel) } end |
#destroy ⇒ Object
Removes all channels and clears authentication.
36 37 38 39 |
# File 'lib/sinapse/channels.rb', line 36 def destroy channels.each { |channel| remove_channel(channel) } auth.clear end |
#has_channel?(channel) ⇒ Boolean
12 13 14 |
# File 'lib/sinapse/channels.rb', line 12 def has_channel?(channel) Sinapse.redis { |redis| redis.sismember(key, channel_for(channel)) } end |
#key(extra = nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/sinapse/channels.rb', line 45 def key(extra = nil) key = "sinapse:channels:#{record.to_param}" key += ":#{extra}" if extra key end |