Class: DTask::RemoteBox

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

Overview

Remote box.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRemoteBox

Returns a new instance of RemoteBox.



33
34
35
36
37
38
# File 'lib/dtask.rb', line 33

def initialize
  @session = Net::SSH.start(Config.server, Config.user)
  @shell = @session.shell.sync
  @out = []
  @err = []
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



31
32
33
# File 'lib/dtask.rb', line 31

def err
  @err
end

#outObject (readonly)

Returns the value of attribute out.



31
32
33
# File 'lib/dtask.rb', line 31

def out
  @out
end

Instance Method Details

#cd_appdirObject

Change the current to application directory.



62
63
64
# File 'lib/dtask.rb', line 62

def cd_appdir
  l "cd #{Config.appdir} && pwd"
end

#l(cmd) ⇒ Object

Run the command or call the task.



41
42
43
# File 'lib/dtask.rb', line 41

def l(cmd)
  cmd.kind_of?(Symbol) ? DTask.run(cmd) : sh(cmd)
end

#l!(cmd) ⇒ Object

Ignore errors.



46
47
48
# File 'lib/dtask.rb', line 46

def l!(cmd)
  begin l(cmd) rescue Error end
end

#sh(cmd) ⇒ Object

Run the command.



51
52
53
54
55
56
57
58
59
# File 'lib/dtask.rb', line 51

def sh(cmd)
  puts "% #{cmd}"
  res = @shell.send_command(cmd)
  pout res.stdout if res.stdout and res.stdout.size > 0
  perr res.stderr if res.stderr and res.stderr.size > 0
  @out << res.stdout
  @err << res.stderr
  res.status == 0 ? res.stdout : (raise Error)
end