Class: RemoteRuby::ExecutionContext

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(**params) ⇒ ExecutionContext

rubocop:disable Metrics/CyclomaticComplexity


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/remote_ruby/execution_context.rb', line 16

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

rubocop:enable Metrics/CyclomaticComplexity


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