Class: Vagrant::Config::VMConfig::Provisioner
- Inherits:
-
Object
- Object
- Vagrant::Config::VMConfig::Provisioner
- Defined in:
- lib/vagrant/config/vm/provisioner.rb
Overview
Represents a single configured provisioner for a VM.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#provisioner ⇒ Object
readonly
Returns the value of attribute provisioner.
-
#shortcut ⇒ Object
readonly
Returns the value of attribute shortcut.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
-
#configure(options = nil, &block) ⇒ Object
Configures the provisioner if it can (if it is valid).
-
#initialize(top, shortcut, options = nil, &block) ⇒ Provisioner
constructor
A new instance of Provisioner.
- #validate(errors) ⇒ Object
Constructor Details
#initialize(top, shortcut, options = nil, &block) ⇒ Provisioner
Returns a new instance of Provisioner.
11 12 13 14 15 16 17 18 19 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 11 def initialize(top, shortcut, =nil, &block) @top = top @shortcut = shortcut @provisioner = shortcut @provisioner = Provisioners::Base.registered[shortcut] if shortcut.is_a?(Symbol) @config = nil configure(, &block) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 9 def config @config end |
#provisioner ⇒ Object (readonly)
Returns the value of attribute provisioner.
8 9 10 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 8 def provisioner @provisioner end |
#shortcut ⇒ Object (readonly)
Returns the value of attribute shortcut.
7 8 9 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 7 def shortcut @shortcut end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
6 7 8 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 6 def top @top end |
Instance Method Details
#configure(options = nil, &block) ⇒ Object
Configures the provisioner if it can (if it is valid).
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 22 def configure(=nil, &block) # We don't want ancestors to be searched. This is the default in 1.8, # but not in 1.9, hence this hackery. const_args = ["Config"] const_args << false if RUBY_VERSION >= "1.9" # We assume that every provisioner has a `Config` class beneath # it for configuring. return if !@provisioner || !@provisioner.const_defined?(*const_args) # Instantiate the config class and configure it @config = @provisioner.const_get(*const_args).new @config.top = top @config.() if block.call(@config) if block end |
#validate(errors) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vagrant/config/vm/provisioner.rb', line 39 def validate(errors) if !provisioner # If we don't have a provisioner then the whole thing is invalid. errors.add(I18n.t("vagrant.config.vm.provisioner_not_found", :shortcut => shortcut)) return end if !(provisioner <= Provisioners::Base) errors.add(I18n.t("vagrant.config.vm.provisioner_invalid_class", :shortcut => shortcut)) end # Pass on validation to the provisioner config config.validate(errors) if config end |