Class: Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(host, user, identity_file) ⇒ Connection

Returns a new instance of Connection.



2
3
4
5
6
# File 'lib/ukku/connection.rb', line 2

def initialize(host, user, identity_file)
  @host = host
  @user = user
  @identity_file = identity_file
end

Instance Method Details

#execute(command, &blk) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ukku/connection.rb', line 8

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