class Kamaze::Project::Tools::Vagrant::Remote

Provide remote command execution (ssh)

Commands can use aliases through configuration: “box_id.ssh.aliases“; where “box_id“ is the box identifier.

Attributes

boxes[R]

@return [Hash]

Public Class Methods

new(boxes, options = {}) click to toggle source

Initialize remote shell with given boxes and options

@param [Hash] boxes @param [Hash] options

Calls superclass method
# File lib/kamaze/project/tools/vagrant/remote.rb, line 29
def initialize(boxes, options = {})
  @boxes = boxes

  super(options)
end

Public Instance Methods

execute(*params, &block) click to toggle source

Run a command remotely on box identified by “box_id“

Sample of use:

“`ruby remote.execute(:freebsd) remote.execute(:freebsd, 'rake clobber') “`

At least, one argument is required.

Calls superclass method
# File lib/kamaze/project/tools/vagrant/remote.rb, line 50
def execute(*params, &block)
  box_id  = params.fetch(0)
  command = apply_alias(box_id, params[1]) # remote command
  params  = command ? [box_id, '-c', command] : [box_id]

  super(*params, &block)
end
to_a() click to toggle source

@return [Array]

Calls superclass method
# File lib/kamaze/project/tools/vagrant/remote.rb, line 36
def to_a
  super.push('ssh')
end

Protected Instance Methods

apply_alias(box_id, command) click to toggle source

Apply alias on command for given “box_id“

@param [String] box_id @param [String|nil] command @return [String|nil]

# File lib/kamaze/project/tools/vagrant/remote.rb, line 65
def apply_alias(box_id, command)
  return unless command

  conf = boxes.fetch(box_id.to_s) # fetch related config
  args = Shellwords.split(command) # command split into words
  exeb = conf['ssh']['aliases'][args[0]] # executable
  if exeb
    command = Shellwords.split(exeb)
                        .concat(args.drop(1))
                        .yield_self { |c| Shellwords.shelljoin(c) }
  end

  command
end