class Sinapse::Channels

TODO: access_token to return the current user token (or generate one if missing)

Public Instance Methods

add_channel(channel) click to toggle source
# 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() click to toggle source
# File lib/sinapse/channels.rb, line 4
def auth
  @auth ||= Authentication.new(record)
end
channel_for(record) click to toggle source
# File lib/sinapse/channels.rb, line 41
def channel_for(record)
  record.is_a?(String) ? record : record.sinapse_channel
end
channels() click to toggle source
# File lib/sinapse/channels.rb, line 8
def channels
  Sinapse.redis { |redis| redis.smembers(key) }
end
clear() click to toggle source

Removes all channels at once.

# File lib/sinapse/channels.rb, line 31
def clear
  channels.each { |channel| remove_channel(channel) }
end
destroy() click to toggle source

Removes all channels and clears authentication.

# File lib/sinapse/channels.rb, line 36
def destroy
  channels.each { |channel| remove_channel(channel) }
  auth.clear
end
has_channel?(channel) click to toggle source
# File lib/sinapse/channels.rb, line 12
def has_channel?(channel)
  Sinapse.redis { |redis| redis.sismember(key, channel_for(channel)) }
end
key(extra = nil) click to toggle source
# File lib/sinapse/channels.rb, line 45
def key(extra = nil)
  key = "sinapse:channels:#{record.to_param}"
  key += ":#{extra}" if extra
  key
end
remove_channel(channel) click to toggle source
# File lib/sinapse/channels.rb, line 23
def remove_channel(channel)
  Sinapse.redis do |redis|
    redis.srem(key, channel_for(channel))
    redis.publish(key(:remove), channel_for(channel))
  end
end