Class: RemoteRuby::Runner
- Inherits:
-
Object
- Object
- RemoteRuby::Runner
- Defined in:
- lib/remote_ruby/runner.rb
Overview
Runner class is responsible for running a prepared Ruby code with given connection adapter, reading output and unmarshalling result and local variables values.
Instance Method Summary collapse
-
#initialize(code:, adapter:, out_stream: $stdout, err_stream: $stderr) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(code:, adapter:, out_stream: $stdout, err_stream: $stderr) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 |
# File 'lib/remote_ruby/runner.rb', line 12 def initialize(code:, adapter:, out_stream: $stdout, err_stream: $stderr) @code = code @adapter = adapter @out_stream = out_stream @err_stream = err_stream end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/remote_ruby/runner.rb', line 19 def run locals = nil adapter.open(code) do |stdout, stderr| out_thread = read_stream(stdout, out_stream, :green) err_thread = read_stream(stderr, err_stream, :red) [out_thread, err_thread].each(&:join) locals = out_thread[:locals] end { result: locals[:__return_val__], locals: locals } end |