Class: Kamaze::Project::Tools::Vagrant
- Inherits:
-
BaseTool
- Object
- Observable
- BaseTool
- Kamaze::Project::Tools::Vagrant
- 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
-
#composer ⇒ Composer
readonly
protected
Get composer, responsible to read and combine files describing boxes.
-
#executable ⇒ String|nil
Absolute path to the vagrant executable.
- #observer_peers ⇒ Hash|nil included from Concern::Observable readonly protected
-
#path ⇒ String
Path to files describing boxes (directory).
-
#shell ⇒ Shell
readonly
protected
Get a shell, to execute
vagrant
commands. -
#template ⇒ String
Template file (used for code generation).
-
#vagrantfile ⇒ Pathname
Get path to actual
Vagrantfile
. -
#writer ⇒ Writer
readonly
protected
Get writer, reponsible of
Vagrantfile
generation.
Instance Method Summary collapse
-
#executable? ⇒ Boolean
Denote
vagrant
executable is present. -
#execute(*args, &block) ⇒ Object
Run the vagrant command with given
args
. -
#install ⇒ self
Install a new Vagrantfile.
- #method_missing(method, *args, &block) ⇒ Object
- #mutable_attributes ⇒ Object
-
#pwd ⇒ Pathname
Get working dir.
-
#remote ⇒ Remote
protected
Get remote shell provider.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
- #setup ⇒ Object protected
-
#setup_compose ⇒ Object
protected
Initialize most of the tools used internally.
-
#ssh(*args, &block) ⇒ Object
Run a command remotely on box identified by
box_id
.
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
#composer ⇒ Composer (readonly, protected)
Get composer, responsible to read and combine files describing boxes
146 147 148 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 146 def composer @composer end |
#executable ⇒ String|nil
Absolute path to the vagrant executable
65 66 67 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 65 def executable @executable end |
#observer_peers ⇒ Hash|nil (readonly, protected) Originally defined in module Concern::Observable
#path ⇒ String
Path to files describing boxes (directory)
defaults to ./vagrant
77 78 79 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 77 def path @path end |
#shell ⇒ Shell (readonly, protected)
Get a shell, to execute vagrant
commands
151 152 153 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 151 def shell @shell end |
#template ⇒ String
Template file (used for code generation)
60 61 62 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 60 def template @template end |
#vagrantfile ⇒ Pathname
Get path to actual Vagrantfile
70 71 72 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 70 def vagrantfile @vagrantfile end |
#writer ⇒ Writer (readonly, protected)
Get writer, reponsible of Vagrantfile
generation
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
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 |
#install ⇒ self
Install a new Vagrantfile
Vagrant file is installed with additionnal YAML file,
defining boxes
121 122 123 124 125 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 121 def install writer.write(boxes) self end |
#mutable_attributes ⇒ Object
79 80 81 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 79 def mutable_attributes [:path, :executable, :template, :vagrantfile] end |
#pwd ⇒ Pathname
Get working dir
86 87 88 |
# File 'lib/kamaze/project/tools/vagrant.rb', line 86 def pwd Pathname.new(Dir.pwd).realpath end |
#remote ⇒ Remote (protected)
Get remote shell provider
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
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 |
#setup ⇒ Object (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_compose ⇒ Object (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 |