Class: WebConsole::Session
- Inherits:
-
Object
- Object
- WebConsole::Session
- Defined in:
- lib/web_console/session.rb
Overview
A session lets you persist wrap an Evaluator
instance in memory associated with multiple bindings.
Each newly created session is persisted into memory and you can find it later its id
.
A session may be associated with multiple bindings. This is used by the error pages only, as currently, this is the only client that needs to do that.
Constant Summary collapse
- @@inmemory_storage =
{}
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
An unique identifier for every REPL.
Class Method Summary collapse
-
.find(id) ⇒ Object
Finds a persisted session in memory by its id.
-
.from_binding(binding) ⇒ Object
Create a Session from a single binding.
-
.from_exception(exc) ⇒ Object
Create a Session from an exception.
Instance Method Summary collapse
-
#eval(input) ⇒ Object
Evaluate
input
on the current Evaluator associated binding. -
#initialize(bindings) ⇒ Session
constructor
A new instance of Session.
-
#switch_binding_to(index) ⇒ Object
Switches the current binding to the one at specified
index
.
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
An unique identifier for every REPL.
36 37 38 |
# File 'lib/web_console/session.rb', line 36 def id @id end |
Class Method Details
.find(id) ⇒ Object
Finds a persisted session in memory by its id.
Returns a persisted session if found in memory. Raises NotFound error unless found in memory.
20 21 22 |
# File 'lib/web_console/session.rb', line 20 def find(id) inmemory_storage[id] end |
.from_binding(binding) ⇒ Object
Create a Session from a single binding.
30 31 32 |
# File 'lib/web_console/session.rb', line 30 def from_binding(binding) new(binding) end |
.from_exception(exc) ⇒ Object
Create a Session from an exception.
25 26 27 |
# File 'lib/web_console/session.rb', line 25 def from_exception(exc) new(exc.bindings) end |
Instance Method Details
#eval(input) ⇒ Object
Evaluate input
on the current Evaluator associated binding.
Returns a string of the Evaluator output.
49 50 51 |
# File 'lib/web_console/session.rb', line 49 def eval(input) @evaluator.eval(input) end |