class Front::CLI::Vagrant

Attributes

id[R]
path[R]
script[RW]
wait[RW]

Public Class Methods

new(id, path, script) click to toggle source
# File lib/front/cli/vagrant.rb, line 9
def initialize(id, path, script)
  @id = id
  @path = path
  @wait = true
  @script = script
end

Public Instance Methods

capture(cmd) click to toggle source
# File lib/front/cli/vagrant.rb, line 74
def capture(cmd)
  Dir.chdir(path) do
    `vagrant #{cmd}`
  end
end
destroy() click to toggle source
# File lib/front/cli/vagrant.rb, line 20
def destroy
  run('destroy -f')
end
get_log_file() click to toggle source
# File lib/front/cli/vagrant.rb, line 56
def get_log_file
  "#{path}/front.log"
end
reload() click to toggle source
# File lib/front/cli/vagrant.rb, line 24
def reload
  run('reload')
end
run(cmd) click to toggle source
# File lib/front/cli/vagrant.rb, line 60
def run(cmd)
  cmd = "vagrant #{cmd}"
  options = {}
  options[:chdir] = path

  if wait
    pid = Kernel.spawn(cmd, options)
    Process.wait pid
  else
    cmd = "#{cmd} &>> #{get_log_file()} "
    script.enqueue "cd #{path} && #{cmd}"
  end
end
ssh() click to toggle source
# File lib/front/cli/vagrant.rb, line 28
def ssh
  run('ssh')
end
ssh_config() click to toggle source
# File lib/front/cli/vagrant.rb, line 32
def ssh_config
  capture('ssh-config')
end
ssh_port() click to toggle source
# File lib/front/cli/vagrant.rb, line 36
def ssh_port
  output = ssh_config()
  re = /^\s*Port\s*(\d+)$/m

  matches = output.match(re)
  return matches[1] unless matches.nil?
  return '2222'
end
status() click to toggle source
# File lib/front/cli/vagrant.rb, line 45
def status
  output = capture('status')
  re = /^(\w+\s+\w+ \(\w+\))/m
  matches = output.match(re)
  if matches
    return matches[1]
  else
    'pending'
  end
end
up() click to toggle source
# File lib/front/cli/vagrant.rb, line 16
def up
  run('up')
end