Class: RemoteRuby::SSHAdapter
- Inherits:
-
ConnectionAdapter
- Object
- ConnectionAdapter
- RemoteRuby::SSHAdapter
- Defined in:
- lib/remote_ruby/ssh_adapter.rb
Overview
An adapter for executing Ruby code on a remote host via SSH
Constant Summary collapse
- UnableToExecuteError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ruby_executable ⇒ Object
readonly
Returns the value of attribute ruby_executable.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#working_dir ⇒ Object
readonly
Returns the value of attribute working_dir.
Instance Method Summary collapse
- #connection_name ⇒ Object
-
#initialize(host:, working_dir: nil, use_ssh_config_file: true, ruby_executable: 'ruby', **params) ⇒ SSHAdapter
constructor
A new instance of SSHAdapter.
- #open(code, stdin, stdout, stderr) ⇒ Object
Constructor Details
#initialize(host:, working_dir: nil, use_ssh_config_file: true, ruby_executable: 'ruby', **params) ⇒ SSHAdapter
Returns a new instance of SSHAdapter.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 13 def initialize(host:, working_dir: nil, use_ssh_config_file: true, ruby_executable: 'ruby', **params) super @host = host @working_dir = working_dir @config = Net::SSH.configuration_for(@host, use_ssh_config_file) @ruby_executable = ruby_executable @config = @config.merge(params) @user = @config[:user] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 11 def config @config end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 11 def host @host end |
#ruby_executable ⇒ Object (readonly)
Returns the value of attribute ruby_executable.
11 12 13 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 11 def ruby_executable @ruby_executable end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 11 def user @user end |
#working_dir ⇒ Object (readonly)
Returns the value of attribute working_dir.
11 12 13 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 11 def working_dir @working_dir end |
Instance Method Details
#connection_name ⇒ Object
37 38 39 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 37 def connection_name "#{user}@#{host}:#{working_dir || '~'}> " end |
#open(code, stdin, stdout, stderr) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/remote_ruby/ssh_adapter.rb', line 24 def open(code, stdin, stdout, stderr) ret = nil Net::SSH.start(host, nil, config) do |ssh| with_temp_file(code, ssh) do |fname| res = run_code(ssh, fname, stdin, stdout, stderr) raise "Process exited with code #{res}" unless res.zero? ret = get_result(ssh, fname) end end ret end |