cloud-maker 0.1.0.pre → 0.1.1

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/bin/cloud-maker CHANGED
@@ -2,7 +2,6 @@
2
2
  require 'thor'
3
3
  require 'colorize'
4
4
  require 'cloud-maker'
5
- require 'pry'
6
5
 
7
6
  class CloudMakerCLI < Thor
8
7
  include Thor::Actions
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
- require 'stringio'
2
+ require 'deep_merge'
3
3
 
4
4
  module CloudMaker
5
5
  class Config
@@ -24,6 +24,8 @@ module CloudMaker
24
24
  # Public: Gets/Sets extra information about the config to be stored for
25
25
  # archival purposes.
26
26
  attr_accessor :extra_options
27
+ # Internal: Gets/Sets an array of paths to other cloud maker configs to import.
28
+ attr_accessor :imports
27
29
 
28
30
  # Internal: A mime header for the Cloud Init config section of the user data
29
31
  CLOUD_CONFIG_HEADER = %Q|Content-Type: text/cloud-config; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment; filename="cloud-config.yaml"\n\n|
@@ -76,7 +78,12 @@ module CloudMaker
76
78
  cloud_config = cloud_config.dup
77
79
  self.options = extract_cloudmaker_config!(cloud_config)
78
80
  self.includes = extract_includes!(cloud_config)
81
+ self.imports = extract_imports!(cloud_config)
79
82
  self.cloud_config = cloud_config
83
+
84
+ self.imports.reverse.each do |import_path|
85
+ self.import(self.class.from_yaml(import_path))
86
+ end
80
87
  end
81
88
 
82
89
  # Public: Check if the CloudMaker config is in a valid state.
@@ -206,9 +213,6 @@ module CloudMaker
206
213
  end
207
214
 
208
215
 
209
-
210
- private
211
-
212
216
  # Internal: Takes a CloudMaker config and parses out the CloudMaker
213
217
  # specific portions of it. For each key/value it fills in any property
214
218
  # blanks from the DEFAULT_KEY_PROPERTIES. It also deletes the cloud_maker
@@ -273,6 +277,16 @@ module CloudMaker
273
277
  includes
274
278
  end
275
279
 
280
+ # Internal: Takes a CloudMaker config and parses out the imports list.
281
+ #
282
+ # config - A hash that should contain an 'import' key storing an array
283
+ # of paths to import.
284
+ #
285
+ # Returns an Array of URLs
286
+ def extract_imports!(config)
287
+ config.delete('import') || []
288
+ end
289
+
276
290
  # Internal: Generates the shell command necessary to set an environment
277
291
  # variable. It escapes the value but assumes there are no special characters
278
292
  # in the key. If value is an array or a hash it generates an environment
@@ -298,5 +312,22 @@ module CloudMaker
298
312
  "echo \"#{key}=\\\"#{escaped_value}\\\"\" >> /etc/environment"
299
313
  end
300
314
  end
315
+
316
+ # Internal: Deep merges another CloudMaker::Config into this one giving
317
+ # precedence to all values set in this one. Arrays will be merged as
318
+ # imported_array.concat(current_array).uniq.
319
+ #
320
+ # It should be noted that this is not reference safe, ie. objects within
321
+ # cloud_maker_config will end up referenced from this config object as well.
322
+ #
323
+ # cloud_maker_config - The CloudMaker::Config to be imported
324
+ #
325
+ # Returns nothing.
326
+ def import(cloud_maker_config)
327
+ self.options = cloud_maker_config.options.deep_merge!(self.options)
328
+ self.includes = cloud_maker_config.includes.concat(self.includes).uniq
329
+ self.cloud_config = cloud_maker_config.cloud_config.deep_merge!(self.cloud_config)
330
+ self.extra_options = cloud_maker_config.extra_options.deep_merge!(self.extra_options)
331
+ end
301
332
  end
302
333
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
5
- prerelease: 6
4
+ version: 0.1.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan Baxter
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-20 00:00:00.000000000 Z
13
+ date: 2012-08-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colorize
@@ -88,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>'
91
+ - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
- version: 1.3.1
93
+ version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
96
  rubygems_version: 1.8.24