class WebConsole::Session
A session lets you persist an Evaluator
instance in memory
associated with multiple bindings.
Each newly created session is persisted into memory and you can find it
later by 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.
Attributes
An unique identifier for every REPL.
Public Class Methods
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 20 def find(id) inmemory_storage[id] end
Create a Session from an binding or exception in a storage.
The storage is expected to respond to []. The binding is expected in :__web_console_binding and the exception in :__web_console_exception.
Can return nil, if no binding or exception have been preserved in the storage.
# File lib/web_console/session.rb, line 31 def from(storage) if exc = storage[:__web_console_exception] new(ExceptionMapper.new(exc)) elsif binding = storage[:__web_console_binding] new([binding]) end end
# File lib/web_console/session.rb, line 43 def initialize(bindings) @id = SecureRandom.hex(16) @bindings = bindings @evaluator = Evaluator.new(@current_binding = bindings.first) store_into_memory end
Public Instance Methods
Returns context of the current binding
# File lib/web_console/session.rb, line 66 def context(objpath) Context.new(@current_binding).extract(objpath) end
Switches the current binding to the one at specified index
.
Returns nothing.
# File lib/web_console/session.rb, line 61 def switch_binding_to(index) @evaluator = Evaluator.new(@current_binding = @bindings[index.to_i]) end
Private Instance Methods
# File lib/web_console/session.rb, line 72 def store_into_memory inmemory_storage[id] = self end