class Colossus
Top Level Class. The public API of the Gem.
Main Colossus
module
The Version
Constants
- ACTIVE
- AWAY
- DISCONNECTED
- VERSION
Attributes
Public Class Methods
# File lib/colossus/configuration.rb, line 27 def self.config configuration end
rubocop:enable
# File lib/colossus/configuration.rb, line 38 def self.config=(configuration) self.configuration = configuration end
# File lib/colossus/configuration.rb, line 23 def self.configuration @configuration ||= Configuration.new end
Help ? rubocop:disable TrivialAccessors
# File lib/colossus/configuration.rb, line 33 def self.configuration=(configuration) @configuration = configuration end
# File lib/colossus/configuration.rb, line 18 def self.configure yield(configuration) if block_given? configuration end
Initialize Colossus
@param ttl [Integer] the seconds before a user without emitting heartbeat
is considered disconnected
@param engine [Engine] the engine which implements the needed methods
to work with Colossus
@return [Colossus]
# File lib/colossus.rb, line 49 def initialize(ttl = Colossus.config.ttl, engine = Colossus.config.engine, secret = Colossus.config.secret_key, writer_token = Colossus.config.writer_token) @engine = engine.new(ttl.to_i) @engine.add_observer(self) @verifier = Colossus::Verifier.new(secret, writer_token) end
# File lib/colossus/configuration.rb, line 42 def self.reset_configuration @configuration = Configuration.new end
Public Instance Methods
Generate a token for the given user_id
# File lib/colossus.rb, line 103 def generate_user_token(user_id) verifier.generate_user_token(user_id) end
Get the status of a specified user, it analyzes the status
of all the sessions. It returns : - active if one or more clients are active. - away if one or more clients are away. - disconnected.
@param user_id [#to_s] The unique identifier of a user
@return Hash{String => String} User_id key, status value
# File lib/colossus.rb, line 82 def get(user_id) engine.get(user_id.to_s) end
(see get
)
# File lib/colossus.rb, line 93 def get_all engine.get_all end
@param user_ids [Array<#to_s>] An array of user ids (see get
)
# File lib/colossus.rb, line 88 def get_multi(*user_ids) engine.get_multi(*user_ids.map(&:to_s)) end
Reset all the data (useful for specs)
# File lib/colossus.rb, line 98 def reset! engine.reset! end
Set the status of a user on a specificed client. A client could be a Websocket session (if the user has 2 tabs opened) or anything else.
@param user_id [#to_s] The unique identifier of a user @param client_id [#to_s] The unique identifier of a client @param status [#to_s] The status of a the user, it can be active,
away or disconnected.
@return [Boolean] Return true if the status has changed if not false.
# File lib/colossus.rb, line 67 def set(user_id, client_id, status) engine.set(user_id.to_s, client_id.to_s, status.to_s) end
Method used when the engine notify a change
@!visibility private
# File lib/colossus.rb, line 110 def update(user_id, status) changed notify_observers(user_id, status) end