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.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/remote_ruby/execution_context.rb', line 17 def initialize(**params) add_flavours(params) @use_cache = params.delete(:use_cache) || false @save_cache = params.delete(:save_cache) || false @cache_dir = params.delete(:cache_dir) || File.join(Dir.pwd, 'cache') @out_stream = params.delete(:out_stream) || $stdout @err_stream = params.delete(:err_stream) || $stderr @adapter_klass = params.delete(:adapter) || ::RemoteRuby::SSHStdinAdapter @params = params FileUtils.mkdir_p(@cache_dir) end |
Instance Method Details
#execute(locals = nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/remote_ruby/execution_context.rb', line 30 def execute(locals = nil, &block) source = code_source(block) locals ||= extract_locals(block) result = execute_code(source, **locals) assign_locals(locals.keys, result[:locals], block) result[:result] end |