Class: Connection
- Inherits:
-
Object
- Object
- Connection
- Defined in:
- lib/ukku/connection.rb
Instance Method Summary collapse
- #execute(command, &blk) ⇒ Object
-
#initialize(opts) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(opts) ⇒ Connection
Returns a new instance of Connection.
2 3 4 5 6 7 8 |
# File 'lib/ukku/connection.rb', line 2 def initialize(opts) = opts.each_with_object({}) { |(k,v), h| h[k.to_sym] = v } @host = [:host] @user = [:user] @identity_file = [:identity_file] end |
Instance Method Details
#execute(command, &blk) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ukku/connection.rb', line 10 def execute(command, &blk) args = ["ssh"] args << "-t" if blk.nil? if @identity_file args += ["-i", @identity_file ] end args += ["#{@user}@#{@host}", "#{command}"] if blk Subprocess.check_call(args, stdin: Subprocess::PIPE, &blk) else Subprocess.check_call(args) end end |