Class: VagrantPlugins::Babushka::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-babushka/config.rb

Overview

Main configuration object for Vagrant Babushka provisioner

Constant Summary collapse

ARGUMENTS =

Configuration keys that are used as Babushka command-line args

[
  :color,
  :debug,
  :dry_run,
  :show_args,
  :silent,
  :update,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-babushka/config.rb', line 21

def initialize
  super
  @deps = []
  @local_deps_path = UNSET_VALUE
  @bootstrap_branch = UNSET_VALUE
  @bootstrap_url = UNSET_VALUE
  @messages = []

  # Reset all argument values to UNSET_VALUE
  ARGUMENTS.each {|a| self.send "#{a}=".to_sym, UNSET_VALUE }
end

Instance Attribute Details

#bootstrap_branchObject

Returns the value of attribute bootstrap_branch.



15
16
17
# File 'lib/vagrant-babushka/config.rb', line 15

def bootstrap_branch
  @bootstrap_branch
end

#bootstrap_urlObject

Returns the value of attribute bootstrap_url.



15
16
17
# File 'lib/vagrant-babushka/config.rb', line 15

def bootstrap_url
  @bootstrap_url
end

#depsObject

Returns the value of attribute deps.



15
16
17
# File 'lib/vagrant-babushka/config.rb', line 15

def deps
  @deps
end

#local_deps_pathObject

Returns the value of attribute local_deps_path.



15
16
17
# File 'lib/vagrant-babushka/config.rb', line 15

def local_deps_path
  @local_deps_path
end

#messagesObject (readonly)

Returns the value of attribute messages.



16
17
18
# File 'lib/vagrant-babushka/config.rb', line 16

def messages
  @messages
end

Instance Method Details

#argumentsObject

Retrieves a Hash of the command-line argument config values

The returned Hash will have command-line argument names for keys, and the value for the argument as the corresponding value.



62
63
64
# File 'lib/vagrant-babushka/config.rb', line 62

def arguments
  ARGUMENTS.inject(Hash.new) {|hash, key| hash.merge({key => send(key)}) }
end

#finalize!Object

This is called as a last-minute hook that allows the configuration object to finalize itself before it will be put into use. This is a useful place to do some defaults in the case the user didn’t configure something or so on.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant-babushka/config.rb', line 37

def finalize!
  @deps = [] if @deps == UNSET_VALUE
  @local_deps_path  = nil if @local_deps_path  == UNSET_VALUE
  @bootstrap_branch = nil if @bootstrap_branch == UNSET_VALUE

  # Setup bootstrap URL if not set
  if @bootstrap_url == UNSET_VALUE
    @bootstrap_url = "https://babushka.me/up"
    @bootstrap_url += "/#{@bootstrap_branch}" if @bootstrap_branch
  end

  # Set defaults for command-line arguments
  @color = nil if @color == UNSET_VALUE
  @debug = false if @debug == UNSET_VALUE
  @dry_run = false if @dry_run == UNSET_VALUE
  @show_args = false if @show_args == UNSET_VALUE
  @silent = false if @silent == UNSET_VALUE
  @update = true if @update == UNSET_VALUE
end

#local_dep(dep_name, params = {}) ⇒ Object

Meets a local dep on the guest

NOTE: This method is deprecated. Please use the new #meet instead.

* dep_name: The name of the dep to meet
* params:    Parameter options to pass to the dep (optional)


73
74
75
76
# File 'lib/vagrant-babushka/config.rb', line 73

def local_dep(dep_name, params = {})
  @messages << [:warn, "#local_dep is deprecated, use #meet", caller]
  @deps << Dep.new(dep_name, :params => params)
end

#meet(dep_name, options = {}) ⇒ Object

The main method to meet deps on the guest virtual machine

This method adds a single dep to a list of deps to be met on the virtual machine. This method replaces the older #local_dep and #remote_dep, unifying the interface for both remote and local deps.

* dep_name: The name of the dep (excluding source prefix)
* options:  A Hash of options. Valid keys:
     * source: The name of the source containing the dep
               (will be used as a source prefix if provided,
               otherwise no source prefix will be used)
     * params: A Hash of parameters to pass to the dep
               (mapping parameter names as keys to values)


105
106
107
# File 'lib/vagrant-babushka/config.rb', line 105

def meet(dep_name, options = {})
  @deps << Dep.new(dep_name, options)
end

#remote_dep(source, dep_name, params = {}) ⇒ Object

Meets a remote dep on the guest

NOTE: This method is deprecated. Please use the new #meet instead.

* source:   The name of the dep's source (GitHub username)
* dep_name: The name of the dep to meet
* params:   Parameter options to pass to the dep (optional)


86
87
88
89
# File 'lib/vagrant-babushka/config.rb', line 86

def remote_dep(source, dep_name, params = {})
  @messages << [:warn, "#remote_dep is deprecated, use #meet", caller]
  @deps << Dep.new(dep_name, :source => source, :params => params)
end