Class: Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ukku/connection.rb

Instance Method Summary collapse

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)
  options = opts.each_with_object({}) { |(k,v), h| h[k.to_sym] = v }

  @host = options[:host]
  @user = options[:user]
  @identity_file = options[: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