Class: WebConsole::ConsoleSession
- Inherits:
-
Object
- Object
- WebConsole::ConsoleSession
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/web_console/console_session.rb
Overview
Manage and persist (in memory) WebConsole::Slave instances.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- INMEMORY_STORAGE =
In-memory storage for the console sessions. Session preservation is troubled on servers with multiple workers and threads.
{}
Class.new(Error)
- Invalid =
Raised when an operation transition to an invalid state.
Class.new(Error)
Class Method Summary collapse
-
.create ⇒ Object
Creates an already persisted consolse session.
-
.find(pid) ⇒ Object
Finds a session by its pid.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ ConsoleSession
constructor
A new instance of ConsoleSession.
-
#persist ⇒ Object
Explicitly persist the model in the in-memory storage.
-
#persisted? ⇒ Boolean
Returns true if the current session is persisted in the in-memory storage.
-
#to_key ⇒ Object
Returns an Enumerable of all key attributes if any is set, regardless if the object is persisted or not.
Methods included from ActiveModel::Model
Constructor Details
#initialize(attributes = {}) ⇒ ConsoleSession
Returns a new instance of ConsoleSession.
44 45 46 |
# File 'app/models/web_console/console_session.rb', line 44 def initialize(attributes = {}) @slave = WebConsole::Slave.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
84 85 86 87 88 89 90 |
# File 'app/models/web_console/console_session.rb', line 84 def method_missing(name, *args, &block) if @slave.respond_to?(name) delegate_and_call_slave_method(name, *args, &block) else super end end |
Class Method Details
.create ⇒ Object
Creates an already persisted consolse session.
Use this method if you need to persist a session, without providing it any input.
39 40 41 |
# File 'app/models/web_console/console_session.rb', line 39 def create new.persist end |
.find(pid) ⇒ Object
Finds a session by its pid.
Raises WebConsole::ConsoleSession::Expired if there is no such session.
31 32 33 |
# File 'app/models/web_console/console_session.rb', line 31 def find(pid) INMEMORY_STORAGE[pid.to_i] or raise Unavailable, 'Session unavailable' end |
Instance Method Details
#persist ⇒ Object
Explicitly persist the model in the in-memory storage.
49 50 51 |
# File 'app/models/web_console/console_session.rb', line 49 def persist INMEMORY_STORAGE[pid] = self end |
#persisted? ⇒ Boolean
Returns true if the current session is persisted in the in-memory storage.
54 55 56 |
# File 'app/models/web_console/console_session.rb', line 54 def persisted? self == INMEMORY_STORAGE[pid] end |
#to_key ⇒ Object
Returns an Enumerable of all key attributes if any is set, regardless if the object is persisted or not.
60 61 62 |
# File 'app/models/web_console/console_session.rb', line 60 def to_key [pid] if persisted? end |