sparkle_formation 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -5
- data/LICENSE +1 -1
- data/README.md +36 -181
- data/lib/sparkle_formation/error.rb +25 -0
- data/lib/sparkle_formation/sparkle.rb +344 -0
- data/lib/sparkle_formation/sparkle_attribute.rb +34 -19
- data/lib/sparkle_formation/sparkle_collection.rb +149 -0
- data/lib/sparkle_formation/sparkle_formation.rb +302 -174
- data/lib/sparkle_formation/sparkle_struct.rb +0 -17
- data/lib/sparkle_formation/utils.rb +0 -18
- data/lib/sparkle_formation/version.rb +1 -19
- data/lib/sparkle_formation.rb +4 -0
- data/sparkle_formation.gemspec +3 -2
- metadata +23 -5
@@ -1,21 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Chris Roberts <chris@hw-ops.com>
|
3
|
-
# Copyright:: 2013, Heavy Water Operations, LLC
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
1
|
require 'sparkle_formation'
|
20
2
|
|
21
3
|
class SparkleFormation
|
@@ -236,31 +218,64 @@ class SparkleFormation
|
|
236
218
|
end
|
237
219
|
alias_method :no_value!, :_no_value
|
238
220
|
|
221
|
+
# Region generator
|
222
|
+
#
|
223
|
+
# @return [Hash]
|
239
224
|
def _region
|
240
225
|
_ref('AWS::Region')
|
241
226
|
end
|
242
227
|
alias_method :region!, :_region
|
243
228
|
|
229
|
+
# Notification ARNs generator
|
230
|
+
#
|
231
|
+
# @return [Hash]
|
244
232
|
def _notification_arns
|
245
233
|
_ref('AWS::NotificationARNs')
|
246
234
|
end
|
247
235
|
alias_method :notification_arns!, :_notification_arns
|
248
236
|
|
237
|
+
# Account ID generator
|
238
|
+
#
|
239
|
+
# @return [Hash]
|
249
240
|
def _account_id
|
250
241
|
_ref('AWS::AccountId')
|
251
242
|
end
|
252
243
|
alias_method :account_id!, :_account_id
|
253
244
|
|
245
|
+
# Stack ID generator
|
246
|
+
#
|
247
|
+
# @return [Hash]
|
254
248
|
def _stack_id
|
255
249
|
_ref('AWS::StackId')
|
256
250
|
end
|
257
251
|
alias_method :stack_id!, :_stack_id
|
258
252
|
|
253
|
+
# Stack name generator
|
254
|
+
#
|
255
|
+
# @return [Hash]
|
259
256
|
def _stack_name
|
260
257
|
_ref('AWS::StackName')
|
261
258
|
end
|
262
259
|
alias_method :stack_name!, :_stack_name
|
263
260
|
|
261
|
+
# Resource dependency generator
|
262
|
+
#
|
263
|
+
# @param [Symbol, String, Array<Symbol, String>] resource names
|
264
|
+
# @return [Array<String>]
|
265
|
+
def _depends_on(*args)
|
266
|
+
_set('DependsOn', [args].flatten.compact.map{|s| _process_key(s)})
|
267
|
+
end
|
268
|
+
alias_method :depends_on!, :_depends_on
|
269
|
+
|
270
|
+
# Reference output value from nested stack
|
271
|
+
#
|
272
|
+
# @param stack_name [String, Symbol] logical resource name of stack
|
273
|
+
# @apram output_name [String, Symbol] stack output name
|
274
|
+
def _stack_output(stack_name, output_name)
|
275
|
+
_attr(_process_key(stack_name), "Outputs.#{_process_key(output_name)}")
|
276
|
+
end
|
277
|
+
alias_method :stack_output!, :_stack_output
|
278
|
+
|
264
279
|
# Execute system command
|
265
280
|
#
|
266
281
|
# @param command [String]
|
@@ -319,7 +334,7 @@ class SparkleFormation
|
|
319
334
|
# @param args [Object] argument list for registry
|
320
335
|
# @return [self]
|
321
336
|
def registry!(name, *args)
|
322
|
-
|
337
|
+
SparkleFormation::Registry.insert(name, self, *args)
|
323
338
|
end
|
324
339
|
|
325
340
|
# Stack nesting helper method
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'sparkle_formation'
|
2
|
+
|
3
|
+
class SparkleFormation
|
4
|
+
# Provides a collection of sparkles
|
5
|
+
# @todo add unmemoize behavior on collection modification to prevent
|
6
|
+
# leak on long running processes with long lasting collections
|
7
|
+
class SparkleCollection < Sparkle
|
8
|
+
|
9
|
+
# Create a new collection of sparkles
|
10
|
+
#
|
11
|
+
# @return [self]
|
12
|
+
def initialize(*_)
|
13
|
+
@root = nil
|
14
|
+
@sparkles = []
|
15
|
+
end
|
16
|
+
|
17
|
+
# Set the root sparkle which forces highest precedence
|
18
|
+
#
|
19
|
+
# @param sparkle [Sparkle]
|
20
|
+
# @return [self]
|
21
|
+
def set_root(sparkle)
|
22
|
+
@root = sparkle
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add new sparkle to collection
|
27
|
+
#
|
28
|
+
# @param sparkle [Sparkle]
|
29
|
+
# @return [self]
|
30
|
+
def add_sparkle(sparkle, precedence=:high)
|
31
|
+
unless(sparkle.is_a?(Sparkle))
|
32
|
+
raise TypeError.new "Expected type `SparkleFormation::Sparkle` but received `#{sparkle.class}`!"
|
33
|
+
end
|
34
|
+
if(precedence == :high)
|
35
|
+
@sparkles.push(sparkle).uniq!
|
36
|
+
else
|
37
|
+
@sparkles.unshift(sparkle).uniq!
|
38
|
+
end
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
# Remove sparkle from collection
|
43
|
+
#
|
44
|
+
# @param sparkle [Sparkle]
|
45
|
+
# @return [self]
|
46
|
+
def remove_sparkle(sparkle)
|
47
|
+
@sparkles.delete(sparkle)
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Sparkle, NilClass]
|
52
|
+
def sparkle_at(idx)
|
53
|
+
sparkles.at(idx)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Integer]
|
57
|
+
def size
|
58
|
+
sparkles.size
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [TrueClass, FalseClass]
|
62
|
+
def empty?
|
63
|
+
size == 0
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Smash]
|
67
|
+
def components
|
68
|
+
memoize("components_#{checksum}") do
|
69
|
+
Smash.new.tap do |hsh|
|
70
|
+
sparkles.each do |sprkl|
|
71
|
+
hsh.merge!(sprkl.components)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Smash]
|
78
|
+
def dynamics
|
79
|
+
memoize("dynamics_#{checksum}") do
|
80
|
+
Smash.new.tap do |hsh|
|
81
|
+
sparkles.each do |sprkl|
|
82
|
+
hsh.merge!(sprkl.dynamics)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Smash]
|
89
|
+
def registries
|
90
|
+
memoize("registries_#{checksum}") do
|
91
|
+
Smash.new.tap do |hsh|
|
92
|
+
sparkles.each do |sprkl|
|
93
|
+
hsh.merge!(sprkl.registries)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Smash]
|
100
|
+
def templates
|
101
|
+
memoize("templates_#{checksum}") do
|
102
|
+
Smash.new.tap do |hsh|
|
103
|
+
sparkles.each do |sprkl|
|
104
|
+
hsh.merge!(sprkl.templates)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Request item from the store
|
111
|
+
#
|
112
|
+
# @param type [String, Symbol] item type (see: TYPES)
|
113
|
+
# @param name [String, Symbol] name of item
|
114
|
+
# @return [Smash] requested item
|
115
|
+
# @raises [NameError, Error::NotFound]
|
116
|
+
def get(*args)
|
117
|
+
result = nil
|
118
|
+
error = nil
|
119
|
+
sparkles.each do |sprkl|
|
120
|
+
begin
|
121
|
+
result = sprkl.get(*args)
|
122
|
+
rescue Error::NotFound => error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
if(result)
|
126
|
+
result
|
127
|
+
else
|
128
|
+
raise error
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
protected
|
133
|
+
|
134
|
+
# @return [Array<Sparkle>]
|
135
|
+
def sparkles
|
136
|
+
(@sparkles + [@root]).compact
|
137
|
+
end
|
138
|
+
|
139
|
+
# @return [String] checksum of sparkles
|
140
|
+
def checksum
|
141
|
+
Smash.new.tap do |s|
|
142
|
+
sparkles.each_with_index do |v, i|
|
143
|
+
s[i.to_s] = v
|
144
|
+
end
|
145
|
+
end.checksum
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|