Class: RemoteRuby::TmpFileAdapter
- Inherits:
-
ConnectionAdapter
- Object
- ConnectionAdapter
- RemoteRuby::TmpFileAdapter
- Defined in:
- lib/remote_ruby/tmp_file_adapter.rb
Overview
An adapter to expecute Ruby code on the local machine inside a temporary file
Instance Attribute Summary collapse
-
#working_dir ⇒ Object
readonly
Returns the value of attribute working_dir.
Instance Method Summary collapse
- #connection_name ⇒ Object
-
#initialize(working_dir: Dir.pwd) ⇒ TmpFileAdapter
constructor
A new instance of TmpFileAdapter.
- #open(code, stdin, stdout, stderr) ⇒ Object
Constructor Details
#initialize(working_dir: Dir.pwd) ⇒ TmpFileAdapter
Returns a new instance of TmpFileAdapter.
13 14 15 16 |
# File 'lib/remote_ruby/tmp_file_adapter.rb', line 13 def initialize(working_dir: Dir.pwd) super @working_dir = working_dir end |
Instance Attribute Details
#working_dir ⇒ Object (readonly)
Returns the value of attribute working_dir.
11 12 13 |
# File 'lib/remote_ruby/tmp_file_adapter.rb', line 11 def working_dir @working_dir end |
Instance Method Details
#connection_name ⇒ Object
43 44 45 |
# File 'lib/remote_ruby/tmp_file_adapter.rb', line 43 def connection_name "#{ENV.fetch('USER', nil)}@localhost:#{working_dir}> " end |
#open(code, stdin, stdout, stderr) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/remote_ruby/tmp_file_adapter.rb', line 18 def open(code, stdin, stdout, stderr) result = nil stdin = RemoteRuby::CompatIOReader.new(stdin) stdout = RemoteRuby::CompatIOWriter.new(stdout) stderr = RemoteRuby::CompatIOWriter.new(stderr) with_temp_file(code) do |filename| pid = Process.spawn( command(filename), in: stdin.readable, out: stdout.writeable, err: stderr.writeable ) _, status = Process.wait2(pid) raise "Process exited with code #{status}" unless status.success? [stdin, stdout, stderr].each(&:join) result = File.binread(filename) end result end |