class Kamaze::Project::Tools::Vagrant

Vagrant based, this class provides a easy and ready to use wrapper around “vagrant“ executable. VM configuration is easyfied by the use of YAML files.

VM configurations are stored in a single directory (default: “vagrant“) and can be overriden by an “.override.yml“ file. A “Vagrantfile“ is generated upon configurations.

Sample use in Rake task:

“`ruby vagrant = project.tools.fetch(:vagrant)

if vagrant.boxes? and vagrant.executable?

file vagrant.vagrantfile => vagrant.sources do
    vagrant.install
end

end “`

This class is almost a facade based on:

@see yaml.org/YAML_for_ruby.html @see friendsofvagrant.github.io/v1/docs/boxes.html

rubocop:disable Style/Documentation

Attributes

composer[R]

Get composer, responsible to read and combine files describing boxes

@return [Composer]

executable[RW]

Absolute path to the vagrant executable

@return [String|nil]

path[RW]

Path to files describing boxes (directory)

defaults to “./vagrant“

@return [String]

shell[R]

Get a shell, to execute “vagrant“ commands

@return [Shell]

template[RW]

Template file (used for code generation)

@return [String]

vagrantfile[RW]

Get path to actual “Vagrantfile“

@return [Pathname]

writer[R]

Get writer, reponsible of “Vagrantfile“ generation

@return [Writer]

Public Instance Methods

executable?() click to toggle source

Denote “vagrant“ executable is present

@return [Boolean]

# File lib/kamaze/project/tools/vagrant.rb, line 83
def executable?
  shell.executable?
end
execute(*args, &block) click to toggle source

Run the vagrant command with given “args“.

@see github.com/ruby/rake/blob/master/lib/rake/file_utils.rb

# File lib/kamaze/project/tools/vagrant.rb, line 90
def execute(*args, &block)
  shell.execute(*args, &block)
end
install() click to toggle source

Install a new Vagrantfile

Vagrant file is installed with additionnal YAML file, defining “boxes“

@return [self]

# File lib/kamaze/project/tools/vagrant.rb, line 111
def install
  writer.write(boxes)

  self
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/kamaze/project/tools/vagrant.rb, line 117
def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    composer.public_send(method, *args, &block)
  else
    super
  end
end
mutable_attributes() click to toggle source
# File lib/kamaze/project/tools/vagrant.rb, line 69
def mutable_attributes
  [:path, :executable, :template, :vagrantfile]
end
pwd() click to toggle source

Get working dir

@return [Pathname]

# File lib/kamaze/project/tools/vagrant.rb, line 76
def pwd
  Pathname.new(Dir.pwd).realpath
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/kamaze/project/tools/vagrant.rb, line 125
def respond_to_missing?(method, include_private = false)
  return true if composer.respond_to?(method, include_private)

  super
end
ssh(*args, &block) click to toggle source

Run a command remotely on box identified by “box_id“

Sample of use:

“`ruby vagrant.ssh('freebsd', 'rake clobber') “`

# File lib/kamaze/project/tools/vagrant.rb, line 101
def ssh(*args, &block)
  remote.execute(*args, &block)
end

Protected Instance Methods

remote() click to toggle source

Get remote shell provider

@return [Remote]

# File lib/kamaze/project/tools/vagrant.rb, line 169
def remote
  Remote.new(boxes, executable: executable)
end
setup() click to toggle source
# File lib/kamaze/project/tools/vagrant.rb, line 148
def setup
  @template ||= Pathname.new(__dir__).join('..', 'resources').to_s
  @vagrantfile ||= ::Pathname.new(@vagrantfile || pwd.join('Vagrantfile'))
  @executable ||= :vagrant
  @path ||= pwd.join('vagrant').to_s

  setup_compose
end
setup_compose() click to toggle source

Initialize most of the tools used internally

# File lib/kamaze/project/tools/vagrant.rb, line 158
def setup_compose
  @composer = Composer.new(@path)
  @shell = Shell.new(executable: executable)
  @writer = Writer.new(@template, vagrantfile)

  self
end