class Chake::Connection

Public Class Methods

connection_name() click to toggle source
# File lib/chake/connection.rb, line 66
def self.connection_name
  name.split('::').last.downcase
end
get(name) click to toggle source
# File lib/chake/connection.rb, line 76
def self.get(name)
  connection = @connections.find { |b| b.connection_name == name }
  raise ArgumentError, "Invalid connection name: #{name}" unless connection

  connection
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/chake/connection.rb, line 70
def self.inherited(subclass)
  super
  @connections ||= []
  @connections << subclass
end

Public Instance Methods

read_output(io) click to toggle source
# File lib/chake/connection.rb, line 33
def read_output(io)
  io.each_line do |line|
    node.log(line.gsub(/\s*$/, ''))
  end
  io.close
  if $CHILD_STATUS
    status = $CHILD_STATUS.exitstatus
    if status != 0
      raise CommandFailed, [node.hostname, 'FAILED with exit status %<status>d' % { status: status }].join(': ')
    end
  end
end
rsync() click to toggle source
# File lib/chake/connection.rb, line 17
def rsync
  ['rsync']
end
rsync_dest() click to toggle source
# File lib/chake/connection.rb, line 21
def rsync_dest
  "#{node.path}/"
end
run(cmd) click to toggle source
# File lib/chake/connection.rb, line 25
def run(cmd)
  node.log('$ %<command>s' % { command: cmd })
  io = IO.popen(command_runner + ['/bin/sh'], 'w+', err: %i[child out])
  io.write(cmd)
  io.close_write
  read_output(io)
end
run_as_root(cmd) click to toggle source
# File lib/chake/connection.rb, line 50
def run_as_root(cmd)
  if node.remote_username == 'root'
    run(cmd)
  else
    run("sudo #{cmd}")
  end
end
run_shell() click to toggle source
# File lib/chake/connection.rb, line 46
def run_shell
  system(*shell_command)
end
scp() click to toggle source
# File lib/chake/connection.rb, line 9
def scp
  ['scp']
end
scp_dest() click to toggle source
# File lib/chake/connection.rb, line 13
def scp_dest
  ''
end
skip?() click to toggle source
# File lib/chake/connection.rb, line 62
def skip?
  false
end
to_s() click to toggle source
# File lib/chake/connection.rb, line 58
def to_s
  self.class.connection_name
end