Class: Colossus
- Inherits:
-
Object
- Object
- Colossus
- Includes:
- Observable
- Defined in:
- lib/colossus.rb,
lib/colossus/version.rb,
lib/colossus/verifier.rb,
lib/colossus/configuration.rb,
lib/colossus/faye/extension.rb,
lib/colossus/http_writer_client.rb,
lib/colossus/engines/redis/redis.rb,
lib/colossus/simple_writer_server.rb,
lib/colossus/engines/memory/memory.rb,
lib/colossus/engines/memory/client_session.rb,
lib/colossus/engines/memory_monitor/memory.rb,
lib/colossus/engines/memory_thread_safe/memory.rb,
lib/colossus/engines/memory/client_session_store.rb,
lib/colossus/engines/memory_thread_safe/client_session.rb,
lib/colossus/engines/memory_thread_safe/client_session_store.rb
Overview
Main Colossus module
Defined Under Namespace
Modules: Engine, Faye Classes: Configuration, HTTPWriterClient, SimpleWriterServer, Verifier
Constant Summary collapse
- ACTIVE =
'active'.freeze
- AWAY =
'away'.freeze
- DISCONNECTED =
'disconnected'.freeze
- VERSION =
'0.11.0'
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#verifier ⇒ Object
readonly
Returns the value of attribute verifier.
Class Method Summary collapse
- .config ⇒ Object
-
.config=(configuration) ⇒ Object
rubocop:enable.
- .configuration ⇒ Object
-
.configuration=(configuration) ⇒ Object
Help ? rubocop:disable TrivialAccessors.
-
.configure {|configuration| ... } ⇒ Object
class Configuration.
- .reset_configuration ⇒ Object
Instance Method Summary collapse
-
#generate_user_token(user_id) ⇒ Object
Generate a token for the given user_id.
-
#get(user_id) ⇒ Object
Get the status of a specified user, it analyzes the status of all the sessions.
-
#get_all ⇒ Object
Get the status of a specified user, it analyzes the status of all the sessions.
-
#get_multi(*user_ids) ⇒ Object
(see #get).
-
#initialize(ttl = Colossus.config.ttl, engine = Colossus.config.engine, secret = Colossus.config.secret_key, writer_token = Colossus.config.writer_token) ⇒ Colossus
constructor
Initialize Colossus.
-
#reset! ⇒ Object
Reset all the data (useful for specs).
-
#set(user_id, client_id, status) ⇒ Boolean
Set the status of a user on a specificed client.
Constructor Details
#initialize(ttl = Colossus.config.ttl, engine = Colossus.config.engine, secret = Colossus.config.secret_key, writer_token = Colossus.config.writer_token) ⇒ Colossus
Initialize Colossus
49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
38 39 40 |
# File 'lib/colossus.rb', line 38 def engine @engine end |
#verifier ⇒ Object (readonly)
Returns the value of attribute verifier.
38 39 40 |
# File 'lib/colossus.rb', line 38 def verifier @verifier end |
Class Method Details
.config ⇒ Object
27 28 29 |
# File 'lib/colossus/configuration.rb', line 27 def self.config configuration end |
.config=(configuration) ⇒ Object
rubocop:enable
38 39 40 |
# File 'lib/colossus/configuration.rb', line 38 def self.config=(configuration) self.configuration = configuration end |
.configuration ⇒ Object
23 24 25 |
# File 'lib/colossus/configuration.rb', line 23 def self.configuration @configuration ||= Configuration.new end |
.configuration=(configuration) ⇒ Object
Help ? rubocop:disable TrivialAccessors
33 34 35 |
# File 'lib/colossus/configuration.rb', line 33 def self.configuration=(configuration) @configuration = configuration end |
.configure {|configuration| ... } ⇒ Object
class Configuration
18 19 20 21 |
# File 'lib/colossus/configuration.rb', line 18 def self.configure yield(configuration) if block_given? configuration end |
.reset_configuration ⇒ Object
42 43 44 |
# File 'lib/colossus/configuration.rb', line 42 def self.reset_configuration @configuration = Configuration.new end |
Instance Method Details
#generate_user_token(user_id) ⇒ Object
Generate a token for the given user_id
103 104 105 |
# File 'lib/colossus.rb', line 103 def generate_user_token(user_id) verifier.generate_user_token(user_id) end |
#get(user_id) ⇒ Object
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.
82 83 84 |
# File 'lib/colossus.rb', line 82 def get(user_id) engine.get(user_id.to_s) end |
#get_all ⇒ Object
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.
93 94 95 |
# File 'lib/colossus.rb', line 93 def get_all engine.get_all end |
#get_multi(*user_ids) ⇒ Object
(see #get)
88 89 90 |
# File 'lib/colossus.rb', line 88 def get_multi(*user_ids) engine.get_multi(*user_ids.map(&:to_s)) end |
#reset! ⇒ Object
Reset all the data (useful for specs)
98 99 100 |
# File 'lib/colossus.rb', line 98 def reset! engine.reset! end |
#set(user_id, client_id, status) ⇒ Boolean
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.
67 68 69 |
# 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 |