Class: Tomo::SSH::Connection
- Inherits:
-
Object
- Object
- Tomo::SSH::Connection
- Defined in:
- lib/tomo/ssh/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, options, exec_proc: nil, child_proc: nil) ⇒ Connection
constructor
A new instance of Connection.
- #ssh_exec(script) ⇒ Object
- #ssh_subprocess(script, verbose: false) ⇒ Object
Constructor Details
#initialize(host, options, exec_proc: nil, child_proc: nil) ⇒ Connection
Returns a new instance of Connection.
16 17 18 19 20 21 |
# File 'lib/tomo/ssh/connection.rb', line 16 def initialize(host, , exec_proc: nil, child_proc: nil) @host = host @options = @exec_proc = exec_proc || Process.method(:exec) @child_proc = child_proc || ChildProcess.method(:execute) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
14 15 16 |
# File 'lib/tomo/ssh/connection.rb', line 14 def host @host end |
Class Method Details
.dry_run(host, options) ⇒ Object
10 11 12 |
# File 'lib/tomo/ssh/connection.rb', line 10 def self.dry_run(host, ) new(host, , exec_proc: proc { CLI.exit }, child_proc: proc { Result.empty_success }) end |
Instance Method Details
#close ⇒ Object
43 44 45 |
# File 'lib/tomo/ssh/connection.rb', line 43 def close FileUtils.rm_f(control_path) end |
#ssh_exec(script) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tomo/ssh/connection.rb', line 23 def ssh_exec(script) ssh_args = build_args(script) logger.script_start(script) Tomo.logger.debug ssh_args.map(&:shellescape).join(" ") exec_proc.call(*ssh_args) end |
#ssh_subprocess(script, verbose: false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tomo/ssh/connection.rb', line 30 def ssh_subprocess(script, verbose: false) ssh_args = build_args(script, verbose:) handle_data = ->(data) { logger.script_output(script, data) } logger.script_start(script) result = child_proc.call(*ssh_args, on_data: handle_data) logger.script_end(script, result) raise_run_error(script, ssh_args, result) if result.failure? && script.raise_on_error? result end |