vagrant-config_builder 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,6 +1,18 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 0.6.0
5
+ -----
6
+
7
+ 2013-10-17
8
+
9
+ This is a backwards incompatible feature release.
10
+
11
+ * Loader::YAML#yamldir can now accept a list of directories to use for
12
+ configuration.
13
+
14
+ Thanks to Charlie Sharpsteen for his help on this release.
15
+
4
16
  0.5.0
5
17
  -----
6
18
 
@@ -0,0 +1 @@
1
+ Vagrant.configure('2', &ConfigBuilder.load(:yaml, :yamldir, '/path/to/config'))
@@ -2,22 +2,28 @@ require 'yaml'
2
2
 
3
3
  class ConfigBuilder::Loader::YAML
4
4
 
5
- # Load configuration from all files in a given directory
5
+ # Load configuration from YAML files in one or more directories
6
6
  #
7
- # @param dir_path [String]
7
+ # @overload yamldir(path)
8
+ # @param path [String] A directory path containing YAML files
9
+ # @overload yamldir(paths)
10
+ # @param paths [Array<String>] A list of directory paths containing YAML files
8
11
  #
9
12
  # @return [Hash]
10
- def yamldir(dir_path)
11
- glob_path = File.join(dir_path, '*.{yml,yaml}')
13
+ def yamldir(input)
14
+ dirs = Array(input)
15
+
16
+ files = dirs.map do |dir|
17
+ pattern = File.join(dir, '*.{yml,yaml}')
18
+ Dir.glob(pattern)
19
+ end.flatten
12
20
 
13
21
  rv = {}
14
- Dir.glob(glob_path).each do |file|
15
- contents = ::YAML.load_file(file)
16
22
 
23
+ files.each do |file|
24
+ contents = ::YAML.load_file(file)
17
25
  if contents.is_a? Hash
18
26
  rv.merge! contents
19
- else
20
- # TODO warn on non-hash YAML
21
27
  end
22
28
  end
23
29
 
@@ -72,6 +72,21 @@ class ConfigBuilder::Model::Base
72
72
  end
73
73
  private :attr
74
74
 
75
+ # Conditionally evaluate a block with a model attribute if it's defined
76
+ #
77
+ # @since 0.6.0
78
+ #
79
+ # @param identifier [Symbol] The attribute identifier
80
+ #
81
+ # @return [void]
82
+ def with_attr(identifier)
83
+ val = @attrs[identifier]
84
+ unless val.nil?
85
+ yield val
86
+ end
87
+ end
88
+ private :with_attr
89
+
75
90
  class << self
76
91
 
77
92
  # @param identifier [Symbol]
@@ -20,13 +20,13 @@ class ConfigBuilder::Model::Provider::Virtualbox < ConfigBuilder::Model::Base
20
20
  def to_proc
21
21
  Proc.new do |vm_config|
22
22
  vm_config.provider 'virtualbox' do |vb_config|
23
- vb_config.name = attr(:name) if attr(:name)
23
+ with_attr(:name) { |val| vb_config.name = val }
24
24
 
25
25
  attr(:customize).each do |cmd|
26
26
  vb_config.customize cmd
27
27
  end
28
28
 
29
- vb_config.gui = attr(:gui) if attr(:gui)
29
+ with_attr(:gui) { |val| vb_config.gui = val }
30
30
  end
31
31
  end
32
32
  end
@@ -24,11 +24,11 @@ class ConfigBuilder::Model::Provisioner::Puppet < ConfigBuilder::Model::Base
24
24
  def to_proc
25
25
  Proc.new do |vm_config|
26
26
  vm_config.provision :puppet do |puppet_config|
27
- puppet_config.manifests_path = attr(:manifests_path) if attr(:manifests_path)
28
- puppet_config.manifest_file = attr(:manifest_file) if attr(:manifest_file)
29
- puppet_config.module_path = attr(:module_path) if attr(:module_path)
30
- puppet_config.facter = attr(:facter) if attr(:facter)
31
- puppet_config.options = attr(:options) if attr(:options)
27
+ with_attr(:manifests_path) { |val| puppet_config.manifests_path = val }
28
+ with_attr(:manifest_file) { |val| puppet_config.manifest_file = val }
29
+ with_attr(:module_path) { |val| puppet_config.module_path = val }
30
+ with_attr(:facter) { |val| puppet_config.facter = val }
31
+ with_attr(:options) { |val| puppet_config.options = val }
32
32
  end
33
33
  end
34
34
  end
@@ -16,9 +16,9 @@ class ConfigBuilder::Model::Provisioner::PuppetServer < ConfigBuilder::Model::Ba
16
16
  def to_proc
17
17
  Proc.new do |vm_config|
18
18
  vm_config.provision :puppet_server do |puppet_config|
19
- puppet_config.puppet_server = attr(:puppet_server) if attr(:puppet_server)
20
- puppet_config.node_name = attr(:node_name) if attr(:node_name)
21
- puppet_config.options = attr(:options) if attr(:options)
19
+ with_attr(:puppet_server) { |val| puppet_config.puppet_server = val }
20
+ with_attr(:node_name) { |val| puppet_config.node_name = val }
21
+ with_attr(:options) { |val| puppet_config.options = val }
22
22
  end
23
23
  end
24
24
  end
@@ -16,9 +16,9 @@ class ConfigBuilder::Model::Provisioner::Shell < ConfigBuilder::Model::Base
16
16
  def to_proc
17
17
  Proc.new do |vm_config|
18
18
  vm_config.provision :shell do |shell_config|
19
- shell_config.inline = attr(:inline) if attr(:inline)
20
- shell_config.path = attr(:path) if attr(:path)
21
- shell_config.args = attr(:args) if attr(:args)
19
+ with_attr(:inline) { |val| shell_config.inline = val }
20
+ with_attr(:path) { |val| shell_config.path = val }
21
+ with_attr(:args) { |val| shell_config.args = val }
22
22
  end
23
23
  end
24
24
  end
@@ -34,9 +34,9 @@ class ConfigBuilder::Model::SyncedFolder < ConfigBuilder::Model::Base
34
34
 
35
35
  def folder_opts
36
36
  h = {}
37
- h[:extra] = attr(:extra) if attr(:extra)
38
- h[:disabled] = attr(:disabled) if attr(:disabled)
39
- h[:nfs] = attr(:nfs) if attr(:nfs)
37
+ with_attr(:extra) { |val| h[:extra] = val }
38
+ with_attr(:disable) { |val| h[:disabled] = val }
39
+ with_attr(:nfs) { |val| h[:nfs] = val }
40
40
 
41
41
  h
42
42
  end
@@ -96,10 +96,10 @@ class ConfigBuilder::Model::VM < ConfigBuilder::Model::Base
96
96
  global_config.vm.define(attr(:name)) do |config|
97
97
  vm_config = config.vm
98
98
 
99
- vm_config.box = attr(:box) if defined? attr(:box)
100
- vm_config.box_url = attr(:box_url) if defined? attr(:box_url)
101
- vm_config.hostname = attr(:hostname) if defined? attr(:hostname)
102
- vm_config.guest = attr(:guest) if defined? attr(:guest)
99
+ with_attr(:box) { |val| vm_config.box = attr(:box) }
100
+ with_attr(:box_url) { |val| vm_config.box_url = attr(:box_url) }
101
+ with_attr(:hostname) { |val| vm_config.hostname = attr(:hostname) }
102
+ with_attr(:guest) { |val| vm_config.guest = attr(:guest) }
103
103
 
104
104
  eval_models(vm_config)
105
105
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigBuilder
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-config_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-18 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -37,6 +37,7 @@ files:
37
37
  - Gemfile
38
38
  - LICENSE
39
39
  - README.markdown
40
+ - examples/Vagrantfile
40
41
  - examples/roles.yaml
41
42
  - examples/vms.yaml
42
43
  - lib/config_builder.rb