Class: RemoteRuby::ExecutionContext
- Inherits:
-
Object
- Object
- RemoteRuby::ExecutionContext
- Defined in:
- lib/remote_ruby/execution_context.rb
Overview
This class is responsible for executing blocks on the remote host with the specified adapters. This is the entrypoint to RemoteRuby logic.
Instance Method Summary collapse
- #execute(locals = nil, &block) ⇒ Object
-
#initialize(**params) ⇒ ExecutionContext
constructor
A new instance of ExecutionContext.
Constructor Details
#initialize(**params) ⇒ ExecutionContext
Returns a new instance of ExecutionContext.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/remote_ruby/execution_context.rb', line 20 def initialize(**params) add_plugins(params) configure_streams(params) @dump_code = params.delete(:dump_code) || false @text_mode_builder = RemoteRuby::TextModeBuilder.new( out_tty: out_stream.tty?, err_tty: err_stream.tty?, params: params ) @adapter_builder = RemoteRuby::AdapterBuilder.new(**params) end |
Instance Method Details
#execute(locals = nil, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/remote_ruby/execution_context.rb', line 32 def execute(locals = nil, &block) source = code_source(block) locals ||= extract_locals(block) compiler = build_compiler(source, locals) context = execute_code(compiler) assign_locals(locals.keys, context.locals, block) if context.error? raise RemoteRuby::RemoteError.new( compiler.compiled_code, context, code_path(compiler.code_hash) ) end context.result end |