class WebConsole::Session
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.
Constants
- INMEMORY_STORAGE
Attributes
id[R]
An unique identifier for every REPL.
Public Class Methods
find(id)
click to toggle source
Finds a persisted session in memory by its id.
Returns a persisted session if found in memory. Raises NotFound error unless found in memory.
# File lib/web_console/session.rb, line 19 def find(id) INMEMORY_STORAGE[id] end
from_binding(binding)
click to toggle source
Create a Session from a single binding.
# File lib/web_console/session.rb, line 29 def from_binding(binding) new(binding) end
from_exception(exc)
click to toggle source
Create a Session from an exception.
# File lib/web_console/session.rb, line 24 def from_exception(exc) new(exc.bindings) end
new(bindings)
click to toggle source
# File lib/web_console/session.rb, line 37 def initialize(bindings) @id = SecureRandom.hex(16) @bindings = Array(bindings) @evaluator = Evaluator.new(@bindings[0]) store_into_memory end
Public Instance Methods
eval(input)
click to toggle source
switch_binding_to(index)
click to toggle source
Switches the current binding to the one at specified index
.
Returns nothing.
# File lib/web_console/session.rb, line 55 def switch_binding_to(index) @evaluator = Evaluator.new(@bindings[index.to_i]) end
Private Instance Methods
store_into_memory()
click to toggle source
# File lib/web_console/session.rb, line 61 def store_into_memory INMEMORY_STORAGE[id] = self end