sparkle_formation 3.0.26 → 3.0.28

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.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +6 -0
  3. data/lib/sparkle_formation/composition.rb +17 -17
  4. data/lib/sparkle_formation/error.rb +2 -5
  5. data/lib/sparkle_formation/function_struct.rb +27 -31
  6. data/lib/sparkle_formation/provider/aws.rb +32 -31
  7. data/lib/sparkle_formation/provider/azure.rb +18 -19
  8. data/lib/sparkle_formation/provider/google.rb +20 -22
  9. data/lib/sparkle_formation/provider/heat.rb +17 -17
  10. data/lib/sparkle_formation/provider/terraform.rb +14 -15
  11. data/lib/sparkle_formation/provider.rb +0 -2
  12. data/lib/sparkle_formation/resources/aws.rb +129 -149
  13. data/lib/sparkle_formation/resources/aws_resources.json +9208 -5542
  14. data/lib/sparkle_formation/resources/azure.rb +2 -5
  15. data/lib/sparkle_formation/resources/azure_resources.json +12367 -2901
  16. data/lib/sparkle_formation/resources/google.rb +1 -4
  17. data/lib/sparkle_formation/resources/heat.rb +0 -4
  18. data/lib/sparkle_formation/resources/heat_resources.json +2616 -2062
  19. data/lib/sparkle_formation/resources/rackspace.rb +0 -4
  20. data/lib/sparkle_formation/resources/terraform.rb +2 -6
  21. data/lib/sparkle_formation/resources.rb +20 -24
  22. data/lib/sparkle_formation/sparkle.rb +56 -66
  23. data/lib/sparkle_formation/sparkle_attribute/aws.rb +61 -34
  24. data/lib/sparkle_formation/sparkle_attribute/azure.rb +12 -8
  25. data/lib/sparkle_formation/sparkle_attribute/google.rb +18 -15
  26. data/lib/sparkle_formation/sparkle_attribute/heat.rb +22 -7
  27. data/lib/sparkle_formation/sparkle_attribute/rackspace.rb +0 -2
  28. data/lib/sparkle_formation/sparkle_attribute/terraform.rb +11 -5
  29. data/lib/sparkle_formation/sparkle_attribute.rb +13 -7
  30. data/lib/sparkle_formation/sparkle_collection/rainbow.rb +5 -7
  31. data/lib/sparkle_formation/sparkle_collection.rb +13 -15
  32. data/lib/sparkle_formation/sparkle_formation.rb +116 -112
  33. data/lib/sparkle_formation/sparkle_struct.rb +30 -24
  34. data/lib/sparkle_formation/translation/heat.rb +57 -58
  35. data/lib/sparkle_formation/translation/rackspace.rb +48 -49
  36. data/lib/sparkle_formation/translation.rb +34 -37
  37. data/lib/sparkle_formation/utils.rb +6 -13
  38. data/lib/sparkle_formation/version.rb +1 -1
  39. data/sparkle_formation.gemspec +1 -1
  40. metadata +9 -9
@@ -2,7 +2,6 @@ require 'sparkle_formation'
2
2
 
3
3
  # Formation container
4
4
  class SparkleFormation
5
-
6
5
  include SparkleFormation::Utils::AnimalStrings
7
6
  # @!parse include SparkleFormation::Utils::AnimalStrings
8
7
  extend SparkleFormation::Utils::AnimalStrings
@@ -12,7 +11,7 @@ class SparkleFormation
12
11
  IGNORE_DIRECTORIES = [
13
12
  'components',
14
13
  'dynamics',
15
- 'registry'
14
+ 'registry',
16
15
  ]
17
16
 
18
17
  # @return [String] default stack resource name
@@ -21,7 +20,6 @@ class SparkleFormation
21
20
  VALID_STACK_RESOURCES = [DEFAULT_STACK_RESOURCE]
22
21
 
23
22
  class << self
24
-
25
23
  include SparkleFormation::Utils::TypeCheckers
26
24
 
27
25
  # @return [Hashish] loaded dynamics
@@ -39,8 +37,8 @@ class SparkleFormation
39
37
  #
40
38
  # @param path [String] path to directory
41
39
  # @return [String] path to directory
42
- def sparkle_path=(path=nil)
43
- if(path)
40
+ def sparkle_path=(path = nil)
41
+ if path
44
42
  custom_paths[:sparkle_path] = path
45
43
  custom_paths[:components_directory] = File.join(path, 'components')
46
44
  custom_paths[:dynamics_directory] = File.join(path, 'dynamics')
@@ -48,42 +46,46 @@ class SparkleFormation
48
46
  end
49
47
  custom_paths[:sparkle_path]
50
48
  end
49
+
51
50
  alias_method(:sparkle_path, :sparkle_path=)
52
51
 
53
52
  # Get/set path to component files
54
53
  #
55
54
  # @param path [String] path to component files
56
55
  # @return [String] path to component files
57
- def components_path=(path=nil)
58
- if(path)
56
+ def components_path=(path = nil)
57
+ if path
59
58
  custom_paths[:components_directory] = path
60
59
  end
61
60
  custom_paths[:components_directory]
62
61
  end
62
+
63
63
  alias_method(:components_path, :components_path=)
64
64
 
65
65
  # Get/set path to dynamic files
66
66
  #
67
67
  # @param path [String] path to dynamic files
68
68
  # @return [String] path to dynamic files
69
- def dynamics_path=(path=nil)
70
- if(path)
69
+ def dynamics_path=(path = nil)
70
+ if path
71
71
  custom_paths[:dynamics_directory] = path
72
72
  end
73
73
  custom_paths[:dynamics_directory]
74
74
  end
75
+
75
76
  alias_method(:dynamics_path, :dynamics_path=)
76
77
 
77
78
  # Get/set path to registry files
78
79
  #
79
80
  # @param path [String] path to registry files
80
81
  # @return [String] path to registry files
81
- def registry_path=(path=nil)
82
- if(path)
82
+ def registry_path=(path = nil)
83
+ if path
83
84
  custom_paths[:registry_directory] = path
84
85
  end
85
86
  custom_paths[:registry_directory]
86
87
  end
88
+
87
89
  alias_method(:registry_path, :registry_path=)
88
90
 
89
91
  # Compile file
@@ -93,16 +95,16 @@ class SparkleFormation
93
95
  # to pass through when compiling ({:state => {}})
94
96
  # @return [Hashish, SparkleStruct]
95
97
  def compile(path, *args)
96
- opts = args.detect{|i| i.is_a?(Hash) } || {}
97
- unless(path.is_a?(String) && File.file?(path.to_s))
98
- if(spath = (opts.delete(:sparkle_path) || SparkleFormation.custom_paths[:sparkle_path]))
98
+ opts = args.detect { |i| i.is_a?(Hash) } || {}
99
+ unless path.is_a?(String) && File.file?(path.to_s)
100
+ if spath = (opts.delete(:sparkle_path) || SparkleFormation.custom_paths[:sparkle_path])
99
101
  container = Sparkle.new(:root => spath)
100
102
  path = container.get(:template, path)[:path]
101
103
  end
102
104
  end
103
105
  formation = instance_eval(IO.read(path), path, 1)
104
106
  formation.template_path = path
105
- if(args.delete(:sparkle))
107
+ if args.delete(:sparkle)
106
108
  formation
107
109
  else
108
110
  formation.compile(opts)._dump
@@ -114,8 +116,8 @@ class SparkleFormation
114
116
  # @param base [SparkleStruct] context for block
115
117
  # @yield block to execute
116
118
  # @return [SparkleStruct] provided base or new struct
117
- def build(base=nil, &block)
118
- if(base || block.nil?)
119
+ def build(base = nil, &block)
120
+ if base || block.nil?
119
121
  struct = base || SparkleStruct.new
120
122
  struct.instance_exec(&block)
121
123
  struct
@@ -171,7 +173,7 @@ class SparkleFormation
171
173
  # :item_name => {:description => 'Defines item name', :type => 'String'}
172
174
  # @yield dynamic block
173
175
  # @return [TrueClass]
174
- def dynamic(name, args={}, &block)
176
+ def dynamic(name, args = {}, &block)
175
177
  @dynamics ||= SparkleStruct.hashish.new
176
178
  dynamics[name] = SparkleStruct.hashish[
177
179
  :block, block, :args, SparkleStruct.hashish[args.map(&:to_a)]
@@ -184,12 +186,13 @@ class SparkleFormation
184
186
  # @param name [String, Symbol] dynamic name
185
187
  # @return [Hashish] metadata information
186
188
  def dynamic_info(name)
187
- if(dynamics[name])
189
+ if dynamics[name]
188
190
  dynamics[name][:args] ||= SparkleStruct.hashish.new
189
191
  else
190
192
  raise KeyError.new("No dynamic registered with provided name (#{name})")
191
193
  end
192
194
  end
195
+
193
196
  alias_method :dynamic_information, :dynamic_info
194
197
 
195
198
  # Insert a dynamic into a context
@@ -200,7 +203,7 @@ class SparkleFormation
200
203
  # @return [SparkleStruct]
201
204
  def registry(registry_name, struct, *args)
202
205
  __t_stringish(registry_name)
203
- opts = args.detect{|item| item.is_a?(Hash)} || {}
206
+ opts = args.detect { |item| item.is_a?(Hash) } || {}
204
207
  reg = struct._self.sparkle.get(:registry, registry_name, opts[:provider])
205
208
  struct.instance_exec(*args, &reg[:block])
206
209
  end
@@ -215,14 +218,14 @@ class SparkleFormation
215
218
  __t_stringish(dynamic_name)
216
219
  result = false
217
220
  begin
218
- opts = args.detect{|i| i.is_a?(Hash)} || {}
221
+ opts = args.detect { |i| i.is_a?(Hash) } || {}
219
222
  dyn = struct._self.sparkle.get(:dynamic, dynamic_name, opts[:provider])
220
223
  opts = nil
221
224
  raise dyn if dyn.is_a?(Exception)
222
225
  dyn.monochrome.each do |dynamic_item|
223
- if(result)
224
- opts = args.detect{|i| i.is_a?(Hash)}
225
- if(opts)
226
+ if result
227
+ opts = args.detect { |i| i.is_a?(Hash) }
228
+ if opts
226
229
  opts[:previous_layer_result] = result
227
230
  else
228
231
  args.push(:previous_layer_result => result)
@@ -230,15 +233,15 @@ class SparkleFormation
230
233
  end
231
234
  result = struct.instance_exec(*args, &dynamic_item[:block])
232
235
  end
233
- if(block_given?)
236
+ if block_given?
234
237
  result.instance_exec(&block)
235
238
  end
236
239
  rescue Error::NotFound::Dynamic
237
240
  result = builtin_insert(dynamic_name, struct, *args, &block)
238
- unless(result)
241
+ unless result
239
242
  message = "Failed to locate requested dynamic block for insertion: #{dynamic_name} " \
240
- "(valid: #{struct._self.sparkle.dynamics.fetch(struct._self.sparkle.provider, {}).keys.sort.join(', ')})"
241
- if(struct._self.provider_resources && struct._self.provider_resources.registry.keys.size > 1)
243
+ "(valid: #{struct._self.sparkle.dynamics.fetch(struct._self.sparkle.provider, {}).keys.sort.join(', ')})"
244
+ if struct._self.provider_resources && struct._self.provider_resources.registry.keys.size > 1
242
245
  t_name = struct._self.provider_resources.registry.keys.first
243
246
  valid_t_name = Bogo::Utility.snake(
244
247
  t_name.split(
@@ -262,8 +265,8 @@ class SparkleFormation
262
265
  # @note if symbol is provided for template, double underscores
263
266
  # will be used for directory separator and dashes will match underscores
264
267
  def nest(template, struct, *args, &block)
265
- options = args.detect{|i| i.is_a?(Hash)}
266
- if(options)
268
+ options = args.detect { |i| i.is_a?(Hash) }
269
+ if options
267
270
  args.delete(options)
268
271
  else
269
272
  options = {}
@@ -273,20 +276,20 @@ class SparkleFormation
273
276
  end
274
277
  to_nest = struct._self.sparkle.get(:template, template, options[:provider])
275
278
  resource_name = template.to_s.gsub('__', '_')
276
- unless(args.empty?)
279
+ unless args.empty?
277
280
  resource_name = [
278
281
  options.delete(:overwrite_name) ? nil : resource_name,
279
- args.map{|a| Bogo::Utility.snake(a)}.join('_')
282
+ args.map { |a| Bogo::Utility.snake(a) }.join('_'),
280
283
  ].flatten.compact.join('_').to_sym
281
284
  end
282
285
  resource_name = struct._process_key(resource_name.to_sym)
283
286
  nested_template = compile(to_nest[:path], :sparkle)
284
287
  nested_template.parent = struct._self
285
288
  nested_template.name = resource_name
286
- if(options[:parameters])
289
+ if options[:parameters]
287
290
  nested_template.compile_state = options[:parameters]
288
291
  end
289
- unless(struct._self.sparkle.empty?)
292
+ unless struct._self.sparkle.empty?
290
293
  nested_template.sparkle.apply(struct._self.sparkle)
291
294
  end
292
295
  nested_resource = struct.dynamic!(
@@ -306,15 +309,15 @@ class SparkleFormation
306
309
  # @param args [Object] parameters for dynamic
307
310
  # @return [SparkleStruct]
308
311
  def builtin_insert(dynamic_name, struct, *args, &block)
309
- if(struct._self.provider_resources && lookup_key = struct._self.provider_resources.registry_key(dynamic_name))
312
+ if struct._self.provider_resources && lookup_key = struct._self.provider_resources.registry_key(dynamic_name)
310
313
  _name, _config = *args
311
314
  _config ||= {}
312
315
  __t_hashish(_config)
313
- unless(_name.is_a?(SparkleFormation::FunctionStruct))
316
+ unless _name.is_a?(SparkleFormation::FunctionStruct)
314
317
  __t_stringish(_name)
315
318
  resource_name = [
316
319
  _name,
317
- _config.fetch(:resource_name_suffix, dynamic_name)
320
+ _config.fetch(:resource_name_suffix, dynamic_name),
318
321
  ].compact.join('_').to_sym
319
322
  else
320
323
  resource_name = _name._root
@@ -323,12 +326,12 @@ class SparkleFormation
323
326
  new_resource = struct.resources.set!(resource_name)
324
327
  new_resource.type lookup_key
325
328
  properties = new_resource.properties
326
- config_keys = _config.keys.zip(_config.keys.map{|k| snake(k).to_s.tr('_', '')})
329
+ config_keys = _config.keys.zip(_config.keys.map { |k| snake(k).to_s.tr('_', '') })
327
330
  struct._self.provider_resources.resource(dynamic_name, :properties).each do |prop_name|
328
- key = (config_keys.detect{|k| k.last == snake(prop_name).to_s.tr('_', '')} || []).first
331
+ key = (config_keys.detect { |k| k.last == snake(prop_name).to_s.tr('_', '') } || []).first
329
332
  value = _config[key] if key
330
- if(value)
331
- if(value.is_a?(Proc))
333
+ if value
334
+ if value.is_a?(Proc)
332
335
  properties.set!(prop_name, &value)
333
336
  else
334
337
  properties.set!(prop_name, value)
@@ -399,26 +402,25 @@ class SparkleFormation
399
402
  # @option options [Hash] :parameters parameters for stack generation
400
403
  # @option options [Truthy, Falsey] :disable_aws_builtins do not load builtins
401
404
  # @yield base context
402
- def initialize(name, options={}, &base_block)
405
+ def initialize(name, options = {}, &base_block)
403
406
  @name = name.to_sym
404
407
  @component_paths = []
405
- if(options[:sparkle_collection])
408
+ if options[:sparkle_collection]
406
409
  @sparkle = options[:sparkle_collection]
407
- if(options[:sparkle])
410
+ if options[:sparkle]
408
411
  @sparkle.add_sparkle(options[:sparkle])
409
412
  end
410
413
  else
411
414
  @sparkle = SparkleCollection.new
412
- if(options[:sparkle])
415
+ if options[:sparkle]
413
416
  @sparkle.set_root(options[:sparkle])
414
417
  else
415
418
  @sparkle.set_root(
416
419
  Sparkle.new(
417
- Smash.new.tap{|h|
420
+ Smash.new.tap { |h|
418
421
  s_path = options.fetch(:sparkle_path,
419
- self.class.custom_paths[:sparkle_path]
420
- )
421
- if(s_path)
422
+ self.class.custom_paths[:sparkle_path])
423
+ if s_path
422
424
  h[:root] = s_path
423
425
  else
424
426
  h[:root] = :none
@@ -429,26 +431,25 @@ class SparkleFormation
429
431
  end
430
432
  end
431
433
  self.provider = options.fetch(:provider, @parent ? @parent.provider : :aws)
432
- if(provider == :aws || !options[:disable_aws_builtins])
434
+ if provider == :aws || !options[:disable_aws_builtins]
433
435
  require 'sparkle_formation/aws'
434
436
  end
435
437
  @parameters = set_generation_parameters!(
436
438
  options.fetch(:compile_time_parameters,
437
- options.fetch(:parameters, {})
438
- )
439
+ options.fetch(:parameters, {}))
439
440
  )
440
441
  @stack_resource_types = [
441
442
  stack_resource_type,
442
- *options.fetch(:stack_resource_types, [])
443
+ *options.fetch(:stack_resource_types, []),
443
444
  ].compact.uniq
444
445
  @blacklisted_templates = [name]
445
446
  @composition = Composition.new(self)
446
447
  @parent = options[:parent]
447
448
  @seed = Smash.new(
448
449
  :inherit => options[:inherit],
449
- :layering => options[:layering]
450
+ :layering => options[:layering],
450
451
  )
451
- if(base_block)
452
+ if base_block
452
453
  load_block(base_block)
453
454
  end
454
455
  @compiled = nil
@@ -462,12 +463,12 @@ class SparkleFormation
462
463
  def seed_self
463
464
  memoize(:seed) do
464
465
  options = @seed
465
- if(options[:inherit] && options[:layering].to_s == 'merge')
466
+ if options[:inherit] && options[:layering].to_s == 'merge'
466
467
  raise ArgumentError.new 'Cannot merge and inherit!'
467
468
  end
468
- if(options[:inherit])
469
+ if options[:inherit]
469
470
  inherit_from(options[:inherit])
470
- elsif(options[:layering].to_s == 'merge')
471
+ elsif options[:layering].to_s == 'merge'
471
472
  merge_previous!
472
473
  end
473
474
  true
@@ -491,7 +492,7 @@ class SparkleFormation
491
492
  # @param template_name [String] name of template to inherit
492
493
  # @return [self]
493
494
  def inherit_from(template_name)
494
- if(blacklisted_templates.map(&:to_s).include?(template_name.to_s))
495
+ if blacklisted_templates.map(&:to_s).include?(template_name.to_s)
495
496
  raise Error::CircularInheritance.new "Circular inheritance detected between templates `#{template_name}` and `#{name}`" # rubocop:disable Metrics/LineLength
496
497
  end
497
498
  template = self.class.compile(sparkle.get(:template, template_name)[:path], :sparkle)
@@ -507,7 +508,7 @@ class SparkleFormation
507
508
  # @return [self]
508
509
  def extract_template_data(template)
509
510
  # TODO: Should allow forced override here for cases like: openstack -> rackspace
510
- if(provider != template.provider)
511
+ if provider != template.provider
511
512
  raise TypeError.new "This template `#{name}` cannot inherit template `#{template.name}`! Provider mismatch: `#{provider}` != `#{template.provider}`" # rubocop:disable Metrics/LineLength
512
513
  end
513
514
  template.sparkle.apply(sparkle)
@@ -517,15 +518,14 @@ class SparkleFormation
517
518
  )
518
519
  @parameters = template.parameters.to_smash.deep_merge(parameters.to_smash)
519
520
  new_composition = Composition.new(self,
520
- :components => template.composition.composite,
521
- :overrides => composition.overrides
522
- )
521
+ :components => template.composition.composite,
522
+ :overrides => composition.overrides)
523
523
  composition.components.each do |item|
524
- if(item.respond_to?(:key) && item.key == '__base__')
524
+ if item.respond_to?(:key) && item.key == '__base__'
525
525
  item.key = Smash.new(
526
526
  :template => name,
527
527
  :component => :__base__,
528
- :object_id => object_id
528
+ :object_id => object_id,
529
529
  ).checksum.to_s
530
530
  end
531
531
  new_composition.add_component(item)
@@ -546,10 +546,10 @@ class SparkleFormation
546
546
  # @param val [String, Symbol, NilClass, FalseClass] remote provider
547
547
  # @return [Symbol, NilClass]
548
548
  def provider=(val)
549
- if(val)
549
+ if val
550
550
  @provider = Bogo::Utility.snake(val).to_sym
551
551
  provider_klass = Bogo::Utility.camel(@provider.to_s)
552
- if(Provider.const_defined?(provider_klass))
552
+ if Provider.const_defined?(provider_klass)
553
553
  extend Provider.const_get(provider_klass)
554
554
  end
555
555
  sparkle.provider = val
@@ -569,7 +569,7 @@ class SparkleFormation
569
569
 
570
570
  # @return [SparkleFormation] root stack
571
571
  def root
572
- if(parent)
572
+ if parent
573
573
  parent.root
574
574
  else
575
575
  self
@@ -578,7 +578,7 @@ class SparkleFormation
578
578
 
579
579
  # @return [Array<SparkleFormation] path to root
580
580
  def root_path
581
- if(parent)
581
+ if parent
582
582
  [*parent.root_path, self].compact
583
583
  else
584
584
  [self]
@@ -594,7 +594,7 @@ class SparkleFormation
594
594
  ALLOWED_GENERATION_PARAMETERS = [
595
595
  'type', 'default', 'description', 'multiple', 'prompt_when_nested',
596
596
  'allowed_values', 'allowed_pattern', 'max_length', 'min_length',
597
- 'max_value', 'min_value'
597
+ 'max_value', 'min_value',
598
598
  ]
599
599
  # Allowed data types for parameters
600
600
  VALID_GENERATION_PARAMETER_TYPES = ['String', 'Number', 'Complex']
@@ -606,10 +606,10 @@ class SparkleFormation
606
606
  # @yieldparam [SparkleFormation]
607
607
  # @return [Proc, NilClass]
608
608
  def compile_time_parameter_setter(&block)
609
- if(block)
609
+ if block
610
610
  @compile_time_parameter_setter = block
611
611
  else
612
- if(@compile_time_parameter_setter)
612
+ if @compile_time_parameter_setter
613
613
  @compile_time_parameter_setter
614
614
  else
615
615
  parent.nil? ? nil : parent.compile_time_parameter_setter
@@ -620,7 +620,7 @@ class SparkleFormation
620
620
  # Set the compile time parameters for the stack if the setter proc
621
621
  # is available
622
622
  def set_compile_time_parameters!
623
- if(compile_time_parameter_setter)
623
+ if compile_time_parameter_setter
624
624
  compile_time_parameter_setter.call(self)
625
625
  end
626
626
  end
@@ -633,10 +633,10 @@ class SparkleFormation
633
633
  # @raises [ArgumentError]
634
634
  def set_generation_parameters!(params)
635
635
  params.each do |name, value|
636
- unless(value.is_a?(Hash))
636
+ unless value.is_a?(Hash)
637
637
  raise TypeError.new("Expecting `Hash` type. Received `#{value.class}`")
638
638
  end
639
- if(key = value.keys.detect{|k| !ALLOWED_GENERATION_PARAMETERS.include?(k.to_s) })
639
+ if key = value.keys.detect { |k| !ALLOWED_GENERATION_PARAMETERS.include?(k.to_s) }
640
640
  raise ArgumentError.new("Invalid generation parameter key provided `#{key}`")
641
641
  end
642
642
  end
@@ -651,6 +651,7 @@ class SparkleFormation
651
651
  composition.new_component(:__base__, &block)
652
652
  true
653
653
  end
654
+
654
655
  alias_method :load_block, :block
655
656
 
656
657
  # Load components into instance
@@ -659,7 +660,7 @@ class SparkleFormation
659
660
  # @return [self]
660
661
  def load(*args, &user_block)
661
662
  args.each do |thing|
662
- if(thing.is_a?(String))
663
+ if thing.is_a?(String)
663
664
  # NOTE: This needs to be deprecated and removed
664
665
  # TODO: deprecate
665
666
  key = File.basename(thing.to_s).sub('.rb', '')
@@ -668,7 +669,7 @@ class SparkleFormation
668
669
  composition.new_component(thing)
669
670
  end
670
671
  end
671
- if(block_given?)
672
+ if block_given?
672
673
  block(user_block)
673
674
  end
674
675
  self
@@ -678,7 +679,7 @@ class SparkleFormation
678
679
  #
679
680
  # @param args [Hash] optional arguments to provide state
680
681
  # @yield override block
681
- def overrides(args={}, &block)
682
+ def overrides(args = {}, &block)
682
683
  composition.new_override(args, &block)
683
684
  self
684
685
  end
@@ -688,8 +689,8 @@ class SparkleFormation
688
689
  # @param args [Hash]
689
690
  # @option args [Hash] :state local state parameters
690
691
  # @return [SparkleStruct]
691
- def compile(args={})
692
- if(args.key?(:state) && args.is_a?(Hash))
692
+ def compile(args = {})
693
+ if args.key?(:state) && args.is_a?(Hash)
693
694
  @compile_state = args[:state].to_smash
694
695
  unmemoize(:compile)
695
696
  end
@@ -698,34 +699,34 @@ class SparkleFormation
698
699
  seed_self
699
700
 
700
701
  set_compile_time_parameters!
701
- if(provider && SparkleStruct.const_defined?(camel(provider)))
702
+ if provider && SparkleStruct.const_defined?(camel(provider))
702
703
  struct_class = SparkleStruct.const_get(camel(provider))
703
704
  struct_name = [SparkleStruct.name, camel(provider)].join('::')
704
- struct_class.define_singleton_method(:name){ struct_name }
705
- struct_class.define_singleton_method(:to_s){ struct_name }
705
+ struct_class.define_singleton_method(:name) { struct_name }
706
+ struct_class.define_singleton_method(:to_s) { struct_name }
706
707
  else
707
708
  struct_class = SparkleStruct
708
709
  end
709
- if(Resources.const_defined?(camel(provider)))
710
+ if Resources.const_defined?(camel(provider))
710
711
  @provider_resources = Resources.const_get(camel(provider))
711
712
  provider_resources.load!
712
713
  end
713
714
  compiled = struct_class.new
714
715
  compiled._set_self(self)
715
716
  compiled._struct_class = struct_class
716
- if(struct_class.const_defined?(:CAMEL_KEYS))
717
+ if struct_class.const_defined?(:CAMEL_KEYS)
717
718
  compiled._camel_keys = struct_class.const_get(:CAMEL_KEYS)
718
719
  end
719
- if(struct_class.const_defined?(:CAMEL_STYLE))
720
+ if struct_class.const_defined?(:CAMEL_STYLE)
720
721
  compiled._camel_style = struct_class.const_get(:CAMEL_STYLE)
721
722
  end
722
- if(compile_state)
723
+ if compile_state
723
724
  compiled.set_state!(compile_state)
724
725
  end
725
726
  composition.each do |item|
726
727
  case item
727
728
  when Composition::Component
728
- if(item.block)
729
+ if item.block
729
730
  self.class.build(compiled, &item.block)
730
731
  else
731
732
  sparkle.get(:component, item.key).monochrome.each do |component_block|
@@ -733,13 +734,13 @@ class SparkleFormation
733
734
  end
734
735
  end
735
736
  when Composition::Override
736
- if(item.args && !item.args.empty?)
737
+ if item.args && !item.args.empty?
737
738
  compiled._set_state(item.args)
738
739
  end
739
740
  self.class.build(compiled, &item.block)
740
741
  end
741
742
  end
742
- if(compile_state && !compile_state.empty?)
743
+ if compile_state && !compile_state.empty?
743
744
  set_compiled_state(compiled)
744
745
  end
745
746
  compiled
@@ -754,11 +755,11 @@ class SparkleFormation
754
755
  def set_compiled_state(compiled)
755
756
  storage_compile_state = Smash.new
756
757
  parameters.each do |param_key, param_config|
757
- if(param_config.fetch(:type, 'string').to_s.downcase.to_sym != :complex)
758
+ if param_config.fetch(:type, 'string').to_s.downcase.to_sym != :complex
758
759
  storage_compile_state[param_key] = compile_state[param_key]
759
760
  end
760
761
  end
761
- unless(storage_compile_state.empty?)
762
+ unless storage_compile_state.empty?
762
763
  compiled.outputs.compile_state.value MultiJson.dump(storage_compile_state)
763
764
  end
764
765
  compiled
@@ -774,15 +775,15 @@ class SparkleFormation
774
775
 
775
776
  # @return [Array<SparkleFormation>]
776
777
  def nested_stacks(*args)
777
- if(compile[:resources])
778
+ if compile[:resources]
778
779
  compile.resources.keys!.map do |key|
779
- if(stack_resource_type?(compile.resources[key].type))
780
- if(!compile.resources[key].properties.stack.nil?)
780
+ if stack_resource_type?(compile.resources[key].type)
781
+ if !compile.resources[key].properties.stack.nil?
781
782
  result = [compile.resources[key].properties.stack]
782
- if(args.include?(:with_resource))
783
+ if args.include?(:with_resource)
783
784
  result.push(compile[:resources][key])
784
785
  end
785
- if(args.include?(:with_name))
786
+ if args.include?(:with_name)
786
787
  result.push(key)
787
788
  end
788
789
  result.size == 1 ? result.first : result
@@ -795,11 +796,11 @@ class SparkleFormation
795
796
  end
796
797
 
797
798
  # @return [TrueClass, FalseClass] includes nested stacks
798
- def nested?(stack_hash=nil)
799
- if(stack_hash)
799
+ def nested?(stack_hash = nil)
800
+ if stack_hash
800
801
  raise Error::Deprecated.new "Hash parameter no longer valid for this method (`#{self.class}##{__callee__}`)"
801
802
  end
802
- unless(compile.resources.nil?)
803
+ unless compile.resources.nil?
803
804
  compile.resources._data.any? do |r_name, r_value|
804
805
  stack_resource_type?(r_value.type)
805
806
  end
@@ -807,11 +808,11 @@ class SparkleFormation
807
808
  end
808
809
 
809
810
  # @return [TrueClass, FalseClass] includes _only_ nested stacks
810
- def isolated_nests?(stack_hash=nil)
811
- if(stack_hash)
811
+ def isolated_nests?(stack_hash = nil)
812
+ if stack_hash
812
813
  raise Error::Deprecated.new "Hash parameter no longer valid for this method (`#{self.class}##{__callee__}`)"
813
814
  end
814
- unless(compile.resources.nil?)
815
+ unless compile.resources.nil?
815
816
  compile.resources._data.all? do |r_name, r_value|
816
817
  stack_resource_type?(r_value.type)
817
818
  end
@@ -819,11 +820,11 @@ class SparkleFormation
819
820
  end
820
821
 
821
822
  # @return [TrueClass, FalseClass] policies defined
822
- def includes_policies?(stack_hash=nil)
823
- if(stack_hash)
823
+ def includes_policies?(stack_hash = nil)
824
+ if stack_hash
824
825
  raise Error::Deprecated.new "Hash parameter no longer valid for this method (`#{self.class}##{__callee__}`)"
825
826
  end
826
- unless(compile.resources.nil?)
827
+ unless compile.resources.nil?
827
828
  compile.resources._data.any? do |r_name, r_value|
828
829
  !r_value.policy.nil?
829
830
  end
@@ -843,7 +844,7 @@ class SparkleFormation
843
844
  # @return [SparkleFormation::SparkleStruct] compiled structure
844
845
  # @note see specific version for expected block parameters
845
846
  def apply_nesting(*args, &block)
846
- if(args.include?(:shallow))
847
+ if args.include?(:shallow)
847
848
  apply_shallow_nesting(&block)
848
849
  else
849
850
  apply_deep_nesting(&block)
@@ -901,7 +902,7 @@ class SparkleFormation
901
902
  # @param x_stacks [Array<Array<SparkleFormation, SparkleStruct, String>>]
902
903
  def stack_template_extractor(x_stacks, &block)
903
904
  x_stacks.each do |stack, resource, s_name|
904
- unless(stack.nested_stacks.empty?)
905
+ unless stack.nested_stacks.empty?
905
906
  stack_template_extractor(stack.nested_stacks(:with_resource, :with_name), &block)
906
907
  end
907
908
  resource.properties._delete(:stack)
@@ -927,8 +928,8 @@ class SparkleFormation
927
928
 
928
929
  # @return [Smash<output_name:SparkleFormation>]
929
930
  def collect_outputs(*args)
930
- if(args.include?(:force) || root?)
931
- if(!compile.outputs.nil? && !root?)
931
+ if args.include?(:force) || root?
932
+ if !compile.outputs.nil? && !root?
932
933
  outputs = Smash[
933
934
  compile.outputs.keys!.zip(
934
935
  [self] * compile.outputs.keys!.size
@@ -938,7 +939,11 @@ class SparkleFormation
938
939
  outputs = Smash.new
939
940
  end
940
941
  nested_stacks.each do |nested_stack|
941
- n_stack = nested_stack.is_a?(self.class) ? nested_stack : nested_stack._self
942
+ if nested_stack.is_a?(self.class) === true
943
+ n_stack = nested_stack
944
+ else
945
+ n_stack = nested_stack._self
946
+ end
942
947
  outputs = n_stack.collect_outputs(:force).merge(outputs)
943
948
  end
944
949
  outputs
@@ -989,5 +994,4 @@ class SparkleFormation
989
994
  end
990
995
  MultiJson.dump(compile.dump!, *args)
991
996
  end
992
-
993
997
  end