sparkle_formation 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0a71f19541a41b7c1939abd94c39a2d9c44389f
4
- data.tar.gz: b49e09f6abe9c535eebe042bb052e8cc87ba91a3
3
+ metadata.gz: f13e8abe07f3752130dc2655eba524647f390618
4
+ data.tar.gz: 874980adb868101566eb4756170280a5a1faec61
5
5
  SHA512:
6
- metadata.gz: 6deda0e42edd85bc7e184840dcbd6e073b31744ca00eae9ab790415bb10b1467d915e4757516d3e863f2e244c4fff554dcbe214b5b137c8ed27694bbefe28187
7
- data.tar.gz: 09960fd747e2d13f97716aa28c790aa2d0716f83ff0d8ae4700a81b13e7d91f326f20957f0435032fac5282fb34ec8991ccb86d5e07975a33e2023ef0f85a3be
6
+ metadata.gz: 5f1cb9bec94362ba83200fb0d9f47ce310799118d3903a565a9b1ac667bb28751a9fdfea0fb952fffce83e3eb6cfbd5af5120672ceb2332b5113547cacc3f724
7
+ data.tar.gz: 5b53d67cb905a968cab3932096e4603b324c68d133d76e66fea82982421b8c96654b4bf09df2db84149634981c14103c811972f44404e597d3e118d7e95e6971
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.4.0
2
+ * Add support for compile time parameters
3
+ * Backport SparkleStruct updates
4
+ * Track parent stack within nested stacks
5
+ * Fix nested stack check method which assumed resources hash
6
+
1
7
  ## v0.3.0
2
8
  * Update `or!` helper method to take multiple arguments
3
9
  * Support non-ref values in `map!` (#19)
@@ -121,9 +121,13 @@ class SparkleFormation
121
121
  # @yield block to execute
122
122
  # @return [SparkleStruct] provided base or new struct
123
123
  def build(base=nil, &block)
124
- struct = base || SparkleStruct.new
125
- struct.instance_exec(&block)
126
- @_struct = struct
124
+ if(base || block.nil?)
125
+ struct = base || SparkleStruct.new
126
+ struct.instance_exec(&block)
127
+ @_struct = struct
128
+ else
129
+ block
130
+ end
127
131
  end
128
132
 
129
133
  # Load component
@@ -132,7 +136,6 @@ class SparkleFormation
132
136
  # @return [SparkleStruct] resulting struct
133
137
  def load_component(path)
134
138
  self.instance_eval(IO.read(path), path, 1)
135
- @_struct
136
139
  end
137
140
 
138
141
  # Load all dynamics within a directory
@@ -226,6 +229,12 @@ class SparkleFormation
226
229
  # @note if symbol is provided for template, double underscores
227
230
  # will be used for directory separator and dashes will match underscores
228
231
  def nest(template, struct, *args, &block)
232
+ options = args.detect{|i| i.is_a?(Hash)}
233
+ if(options)
234
+ args.delete(options)
235
+ else
236
+ options = {}
237
+ end
229
238
  spath = SparkleFormation.new('stub').sparkle_path
230
239
  resource_name = [template.to_s.gsub(/(\/|__|-)/, '_'), *args].compact.join('_').to_sym
231
240
  path = template.is_a?(Symbol) ? template.to_s.gsub('__', '/') : template.to_s
@@ -237,10 +246,12 @@ class SparkleFormation
237
246
  raise ArgumentError.new("Failed to locate nested stack file! (#{template.inspect} -> #{path.inspect})")
238
247
  end
239
248
  instance = self.instance_eval(IO.read(file), file, 1)
249
+ instance.parent = struct._self
250
+ instance.name = Bogo::Utility.camel(resource_name)
240
251
  struct.resources.set!(resource_name) do
241
252
  type 'AWS::CloudFormation::Stack'
242
253
  end
243
- struct.resources.__send__(resource_name).properties.stack instance.compile
254
+ struct.resources.__send__(resource_name).properties.stack instance.compile(:state => options[:parameters])
244
255
  if(block_given?)
245
256
  struct.resources.__send__(resource_name).instance_exec(&block)
246
257
  end
@@ -294,7 +305,7 @@ class SparkleFormation
294
305
  end
295
306
 
296
307
  # @return [Symbol] name of formation
297
- attr_reader :name
308
+ attr_accessor :name
298
309
  # @return [String] base path
299
310
  attr_reader :sparkle_path
300
311
  # @return [String] components path
@@ -309,6 +320,12 @@ class SparkleFormation
309
320
  attr_reader :load_order
310
321
  # @return [Hash] parameters for stack generation
311
322
  attr_reader :parameters
323
+ # @return [Hash] state hash for compile time parameters
324
+ attr_accessor :compile_state
325
+ # @return [Proc] block to call for setting compile time parameters
326
+ attr_accessor :compile_time_parameter_setter
327
+ # @return [SparkleFormation] parent instance
328
+ attr_accessor :parent
312
329
 
313
330
  # Create new instance
314
331
  #
@@ -341,7 +358,11 @@ class SparkleFormation
341
358
  require 'sparkle_formation/aws'
342
359
  SfnAws.load!
343
360
  end
344
- @parameters = set_generation_parameters!(options.fetch(:parameters, {}))
361
+ @parameters = set_generation_parameters!(
362
+ options.fetch(:parameters,
363
+ options.fetch(:compile_time_parameters, {})
364
+ )
365
+ )
345
366
  @components = SparkleStruct.hashish.new
346
367
  @load_order = []
347
368
  @overrides = []
@@ -351,7 +372,33 @@ class SparkleFormation
351
372
  @compiled = nil
352
373
  end
353
374
 
354
- ALLOWED_GENERATION_PARAMETERS = ['type', 'default']
375
+ # Get or set the compile time parameter setting block. If a get
376
+ # request the ancestor path will be searched to root
377
+ #
378
+ # @yield block to set compile time parameters
379
+ # @yieldparam [SparkleFormation]
380
+ # @return [Proc, NilClass]
381
+ def compile_time_parameter_setter(&block)
382
+ if(block)
383
+ @compile_time_parameter_setter = block
384
+ else
385
+ if(@compile_time_parameter_setter)
386
+ @compile_time_parameter_setter
387
+ else
388
+ parent.nil? ? nil : parent.compile_time_parameter_setter
389
+ end
390
+ end
391
+ end
392
+
393
+ # Set the compile time parameters for the stack if the setter proc
394
+ # is available
395
+ def set_compile_time_parameters!
396
+ if(compile_time_parameter_setter)
397
+ compile_time_parameter_setter.call(self)
398
+ end
399
+ end
400
+
401
+ ALLOWED_GENERATION_PARAMETERS = ['type', 'default', 'description', 'multiple', 'prompt_when_nested']
355
402
  VALID_GENERATION_PARAMETER_TYPES = ['String', 'Number']
356
403
 
357
404
  # Validation parameters used for template generation to ensure they
@@ -377,7 +424,7 @@ class SparkleFormation
377
424
  # @param block [Proc]
378
425
  # @return [TrueClass]
379
426
  def block(block)
380
- @components[:__base__] = self.class.build(&block)
427
+ @components[:__base__] = block
381
428
  @load_order << :__base__
382
429
  true
383
430
  end
@@ -416,13 +463,19 @@ class SparkleFormation
416
463
  # @option args [Hash] :state local state parameters
417
464
  # @return [SparkleStruct]
418
465
  def compile(args={})
466
+ if(args.has_key?(:state))
467
+ @compile_state = args[:state]
468
+ @compiled = nil
469
+ end
419
470
  unless(@compiled)
471
+ set_compile_time_parameters!
420
472
  compiled = SparkleStruct.new
421
- if(args[:state])
422
- compiled.set_state!(args[:state])
473
+ compiled._set_self(self)
474
+ if(compile_state)
475
+ compiled.set_state!(compile_state)
423
476
  end
424
477
  @load_order.each do |key|
425
- compiled._merge!(components[key])
478
+ self.class.build(compiled, &components[key])
426
479
  end
427
480
  @overrides.each do |override|
428
481
  if(override[:args] && !override[:args].empty?)
@@ -430,6 +483,9 @@ class SparkleFormation
430
483
  end
431
484
  self.class.build(compiled, &override[:block])
432
485
  end
486
+ if(compile_state)
487
+ compiled.outputs.compile_state.value MultiJson.dump(compile_state)
488
+ end
433
489
  @compiled = compiled
434
490
  end
435
491
  @compiled
@@ -438,14 +494,14 @@ class SparkleFormation
438
494
  # Clear compiled stack if cached and perform compilation again
439
495
  #
440
496
  # @return [SparkleStruct]
441
- def recompile
497
+ def recompile(args={})
442
498
  @compiled = nil
443
- compile
499
+ compile(args)
444
500
  end
445
501
 
446
502
  # @return [TrueClass, FalseClass] includes nested stacks
447
503
  def nested?
448
- !!compile.dump!['Resources'].detect do |r_name, resource|
504
+ !!compile.dump!.fetch('Resources', {}).detect do |r_name, resource|
449
505
  resource['Type'] == 'AWS::CloudFormation::Stack'
450
506
  end
451
507
  end
@@ -1,14 +1,65 @@
1
1
  require 'sparkle_formation'
2
+ require 'attribute_struct/monkey_camels'
2
3
 
3
4
  class SparkleFormation
4
5
  # SparkleFormation customized AttributeStruct
5
6
  class SparkleStruct < AttributeStruct
7
+
6
8
  include ::SparkleFormation::SparkleAttribute
7
9
  # @!parse include ::SparkleFormation::SparkleAttribute
8
10
 
11
+ # Override initializer to force desired behavior
12
+ def initialize(*_)
13
+ super
14
+ @_camel_keys = true
15
+ _set_state :hash_load_struct => true
16
+ end
17
+
18
+ # Set SparkleFormation instance
19
+ #
20
+ # @param inst [SparkleFormation]
21
+ # @return [SparkleFormation]
22
+ def _set_self(inst)
23
+ unless(inst.is_a?(::SparkleFormation))
24
+ ::Kernel.raise ::TypeError.new "Expecting type of `SparkleFormation` but got `#{inst.class}`"
25
+ end
26
+ @self = inst
27
+ end
28
+
29
+ # @return [SparkleFormation]
30
+ def _self(*_)
31
+ unless(@self)
32
+ if(_parent.nil?)
33
+ ::Kernel.raise ::ArgumentError.new 'Creator did not provide return reference!'
34
+ else
35
+ _parent._self
36
+ end
37
+ else
38
+ @self
39
+ end
40
+ end
41
+
9
42
  # @return [Class]
10
43
  def _klass
11
44
  ::SparkleFormation::SparkleStruct
12
45
  end
46
+
47
+ # Override the state to force helpful error when no value has been
48
+ # provided
49
+ #
50
+ # @param arg [String, Symbol] name of parameter
51
+ # @return [Object]
52
+ # @raises [ArgumentError]
53
+ def _state(arg)
54
+ result = super
55
+ if(@self && result.nil?)
56
+ if(_self.parameters.keys.map(&:to_s).include?(arg.to_s))
57
+ ::Kernel.raise ::ArgumentError.new "No value provided for compile time parameter: `#{arg}`!"
58
+ end
59
+ end
60
+ result
61
+ end
62
+ alias_method :state!, :_state
63
+
13
64
  end
14
65
  end
@@ -18,5 +18,5 @@
18
18
 
19
19
  class SparkleFormation
20
20
  # Current library version
21
- VERSION = Gem::Version.new('0.3.0')
21
+ VERSION = Gem::Version.new('0.4.0')
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkle_formation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attribute_struct
@@ -81,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 2.2.2
84
+ rubygems_version: 2.4.8
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Cloud Formation builder
88
88
  test_files: []
89
- has_rdoc: