-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted common behaviour from SSHStdinAdapter and LocalStdinAdapter…
… to ExternalProcessAdapter class
- Loading branch information
Showing
4 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/remote_ruby/connection_adapter/external_process_adapter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'open3' | ||
|
||
module RemoteRuby | ||
# Base class for adapters which launch an external process to execute | ||
# Ruby code. | ||
class ExternalProcessAdapter < ::RemoteRuby::ConnectionAdapter | ||
include Open3 | ||
|
||
# Command to run an external process. Override in a child class. | ||
def command | ||
raise NotImplementedError | ||
end | ||
|
||
def open(code) | ||
result = nil | ||
|
||
popen3(command) do |stdin, stdout, stderr, wait_thr| | ||
stdin.write(code) | ||
stdin.close | ||
|
||
yield stdout, stderr | ||
|
||
result = wait_thr.value | ||
end | ||
|
||
return if result.success? | ||
|
||
raise "Remote connection exited with code #{result}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters