Class: Kamaze::Project::Tools::Vagrant

Inherits:
BaseTool show all
Defined in:
lib/kamaze/project/tools/vagrant.rb,
lib/kamaze/project/tools/vagrant.rb,
lib/kamaze/project/tools/vagrant/shell.rb,
lib/kamaze/project/tools/vagrant/remote.rb,
lib/kamaze/project/tools/vagrant/writer.rb,
lib/kamaze/project/tools/vagrant/composer.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Classes: Composer, Remote, Shell, Writer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::BaseTool

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/kamaze/project/tools/vagrant.rb', line 127

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    composer.public_send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#composerComposer (readonly, protected)

Get composer, responsible to read and combine files describing boxes

Returns:



146
147
148
# File 'lib/kamaze/project/tools/vagrant.rb', line 146

def composer
  @composer
end

#executableString|nil

Absolute path to the vagrant executable

Returns:

  • (String|nil)


65
66
67
# File 'lib/kamaze/project/tools/vagrant.rb', line 65

def executable
  @executable
end

#observer_peersHash|nil (readonly, protected) Originally defined in module Concern::Observable

Returns:

  • (Hash|nil)

#pathString

Path to files describing boxes (directory)

defaults to ./vagrant

Returns:

  • (String)


77
78
79
# File 'lib/kamaze/project/tools/vagrant.rb', line 77

def path
  @path
end

#shellShell (readonly, protected)

Get a shell, to execute vagrant commands

Returns:



151
152
153
# File 'lib/kamaze/project/tools/vagrant.rb', line 151

def shell
  @shell
end

#templateString

Template file (used for code generation)

Returns:

  • (String)


60
61
62
# File 'lib/kamaze/project/tools/vagrant.rb', line 60

def template
  @template
end

#vagrantfilePathname

Get path to actual Vagrantfile

Returns:

  • (Pathname)


70
71
72
# File 'lib/kamaze/project/tools/vagrant.rb', line 70

def vagrantfile
  @vagrantfile
end

#writerWriter (readonly, protected)

Get writer, reponsible of Vagrantfile generation

Returns:



156
157
158
# File 'lib/kamaze/project/tools/vagrant.rb', line 156

def writer
  @writer
end

Instance Method Details

#executable?Boolean

Denote vagrant executable is present

Returns:

  • (Boolean)


93
94
95
# File 'lib/kamaze/project/tools/vagrant.rb', line 93

def executable?
  shell.executable?
end

#execute(*args, &block) ⇒ Object

Run the vagrant command with given args.



100
101
102
# File 'lib/kamaze/project/tools/vagrant.rb', line 100

def execute(*args, &block)
  shell.execute(*args, &block)
end

#installself

Install a new Vagrantfile

Vagrant file is installed with additionnal YAML file, defining boxes

Returns:

  • (self)


121
122
123
124
125
# File 'lib/kamaze/project/tools/vagrant.rb', line 121

def install
  writer.write(boxes)

  self
end

#mutable_attributesObject



79
80
81
# File 'lib/kamaze/project/tools/vagrant.rb', line 79

def mutable_attributes
  [:path, :executable, :template, :vagrantfile]
end

#pwdPathname

Get working dir

Returns:

  • (Pathname)


86
87
88
# File 'lib/kamaze/project/tools/vagrant.rb', line 86

def pwd
  Pathname.new(Dir.pwd).realpath
end

#remoteRemote (protected)

Get remote shell provider

Returns:



179
180
181
# File 'lib/kamaze/project/tools/vagrant.rb', line 179

def remote
  Remote.new(boxes, executable: executable)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'lib/kamaze/project/tools/vagrant.rb', line 135

def respond_to_missing?(method, include_private = false)
  return true if composer.respond_to?(method, include_private)

  super
end

#setupObject (protected)



158
159
160
161
162
163
164
165
# File 'lib/kamaze/project/tools/vagrant.rb', line 158

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_composeObject (protected)

Initialize most of the tools used internally



168
169
170
171
172
173
174
# File 'lib/kamaze/project/tools/vagrant.rb', line 168

def setup_compose
  @composer = Composer.new(@path)
  @shell = Shell.new(executable: executable)
  @writer = Writer.new(@template, vagrantfile)

  self
end

#ssh(*args, &block) ⇒ Object

Run a command remotely on box identified by box_id

Sample of use:

vagrant.ssh('freebsd', 'rake clobber')


111
112
113
# File 'lib/kamaze/project/tools/vagrant.rb', line 111

def ssh(*args, &block)
  remote.execute(*args, &block)
end