Class: Chukan::Remote

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, user = nil, key = nil) ⇒ Remote

Returns a new instance of Remote.



356
357
358
359
360
361
# File 'lib/chukan.rb', line 356

def initialize(host, user = nil, key = nil)
  @host = host
  @user = user
  @key  = key
  @dir  = nil
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



362
363
364
# File 'lib/chukan.rb', line 362

def host
  @host
end

Instance Method Details

#cd(dir = nil) ⇒ Object



364
365
366
367
# File 'lib/chukan.rb', line 364

def cd(dir = nil)
  @dir = dir
  self
end

#command(*cmdline) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/chukan.rb', line 369

def command(*cmdline)
  ssh = ENV["SSH"] || "ssh"
  cmd = [ssh, "-o", "Batchmode yes"]
  cmd += ["-i", @key] if @key
  if @user
    cmd.push "#{@user}:#{@host}"
  else
    cmd.push @host
  end
  if @dir
    cmd += ["cd", @dir, "&&"]
  end
  cmd + cmdline.map {|x| x.to_s }
end

#spawn(*cmdline, &block) ⇒ Object



384
385
386
# File 'lib/chukan.rb', line 384

def spawn(*cmdline, &block)
  RemoteProcess.new(self, *cmdline, &block)
end