sparkle_formation 1.1.6 → 1.1.8

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: d8c8435e87b4a778f623d62924a0e04ce2d12984
4
- data.tar.gz: 8d6ccfaad6cbb84f3e73a3a25f48a12f27d0d4a6
3
+ metadata.gz: cec97d229b916558ac8d3d3dbab3ba9912b7b637
4
+ data.tar.gz: eae3742d180d5a39cffbe79488d7ba48a81421dd
5
5
  SHA512:
6
- metadata.gz: 24eabd02e9e856165565d27e0fcb6b68ff4a1ff4b48d5f364e7709451892bf1923877cdb14b8c72bb6ea5e5b15effdbb62a681abd962f720897c74006f2c98a3
7
- data.tar.gz: a1aaadb1b5237ab15c31e341833cc1cf701597a8bbb8ed0dd277e5955ec3428d54c79718eb5b69465f395281139610a9a413962cdfdd91bcec9ab3f862d5d79c
6
+ metadata.gz: 9d17129d13125c94b53a65f7db3bf98a5158d05d364e0db63c7b96932d160c0199528f186fe44d2087853744fe0f6dddb748ed7f24d40a9275febd2a55461dd6
7
+ data.tar.gz: 06a6b6e7583dd3b99d3ab58660be6619d7ff263717f4c90c36b1742e6ebfdce6cc509038656491d36d5b042aede6b3c410c50831690ccacdb6b5a8b4dcb78bb3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.1.8
2
+ * Raise error on name collisions within pack (#101)
3
+ * Extract registry items from pack during compile
4
+
1
5
  ## v1.1.6
2
6
  * Fix `#root!` helper method usage (#98)
3
7
 
data/README.md CHANGED
@@ -17,114 +17,20 @@ helper functions for commonly generated data structures, builtin
17
17
  logic for handling template nesting, and most importantly:
18
18
  conjouring magic (to get unicorns).
19
19
 
20
- ## Documentation
21
-
22
- * [Library Documentation](https://sparkleformation.github.io/sparkle_formation)
23
- * [User Documentation](https://sparkleformation.github.io/sparkle_formation/UserDocs)
24
-
25
- ## Overview
26
-
27
- Many template orchestration APIs accept serialized templates defining
28
- infrastructure resources and configurations. Interacting directly with
29
- these services via data serialization formats (JSON, YAML, etc) can be
30
- difficult for humans. SparkleFormation allows humans to programmatically
31
- define templates in Ruby. These are then exported into the desired
32
- serialization format, ready to send to the target orchestration API.
33
-
34
- ## What's it look like?
35
-
36
- Below is a simple example of an AWS CloudFormation template defined within
37
- SparkleFormation. It creates a single EC2 resource:
38
-
39
- ```ruby
40
- SparkleFormation.new('ec2_example') do
41
- description "AWS CloudFormation Sample Template ..."
42
-
43
- parameters.key_name do
44
- description 'Name of EC2 key pair'
45
- type 'String'
46
- end
47
-
48
- mappings.region_map do
49
- set!('us-east-1'._no_hump, :ami => 'ami-7f418316')
50
- set!('us-west-1'._no_hump, :ami => 'ami-951945d0')
51
- set!('us-west-2'._no_hump, :ami => 'ami-16fd7026')
52
- set!('eu-west-1'._no_hump, :ami => 'ami-24506250')
53
- set!('sa-east-1'._no_hump, :ami => 'ami-3e3be423')
54
- set!('ap-southeast-1'._no_hump, :ami => 'ami-74dda626')
55
- set!('ap-northeast-1'._no_hump, :ami => 'ami-dcfa4edd')
56
- end
20
+ ## Using SparkleFormation
57
21
 
58
- dynamic!(:ec2_instance, :foobar) do
59
- properties do
60
- key_name ref!(:key_name)
61
- image_id map!(:region_map, region!, :ami)
62
- user_data base64!('80')
63
- end
64
- end
22
+ SparkleFormation is a library and not intended for "direct use". If
23
+ you are looking to build infrastructure stacks via orchestration APIs
24
+ using SparkleFormation templates, please see the reference application
25
+ implementation:
65
26
 
66
- outputs do
67
- instance_id do
68
- description 'InstanceId of the newly created EC2 instance'
69
- value ref!(:foobar_ec2_instance)
70
- end
71
- az do
72
- description 'Availability Zone of the newly created EC2 instance'
73
- value attr!(:foobar_ec2_instance, :availability_zone)
74
- end
75
- public_ip do
76
- description 'Public IP address of the newly created EC2 instance'
77
- value attr!(:foobar_ec2_instance, :public_ip)
78
- end
79
- private_ip do
80
- description 'Private IP address of the newly created EC2 instance'
81
- value attr!(:foobar_ec2_instance, :private_ip)
82
- end
83
- public_dns do
84
- description 'Public DNSName of the newly created EC2 instance'
85
- value attr!(:foobar_ec2_instance, :public_dns_name)
86
- end
87
- private_dns do
88
- description 'Private DNSName of the newly created EC2 instance'
89
- value attr!(:foobar_ec2_instance, :private_dns_name)
90
- end
91
- end
92
- end
93
- ```
27
+ * [SparkleFormation CLI (sfn)](http://www.sparkleformation.io/docs/sfn)
94
28
 
95
- And once compiled we get a nice Hash that we can then convert to JSON which
96
- is ready to send to the AWS CloudFormation API:
97
-
98
- ```ruby
99
- require 'sparkle_formation'
100
- require 'json'
101
-
102
- puts JSON.pretty_generate(
103
- SparkleFormation.compile('ec2_example.rb')
104
- )
105
- ```
106
-
107
- Easy!
108
-
109
- ## Reusability features
110
-
111
- SparkleFormation provides a number of features facilitating code reuse and
112
- logical structuring. These features help aid developers in applying DRY
113
- concepts to infrastructure codebases easing maintainability.
114
-
115
- > [Learn more!](https://sparkleformation.github.io/sparkle_formation/UserDocs/building-blocks.html)
116
-
117
- ## SparkleFormation Implementations
118
-
119
- SparkleFormation itself is simply a library for building complex template
120
- documents in Ruby. It does not provide any integrations with remote API
121
- services. For interacting with remote services using the SparkleFormation
122
- library, see the SparkleFormation CLI application:
29
+ ## Documentation
123
30
 
124
- * [SparkleFormation CLI (sfn)](https://github.com/sparkleformation/sfn)
31
+ * [SparkleFormation Library Documentation](http://www.sparkleformation.io/docs/sparkle_formation/)
125
32
 
126
33
  # Infos
127
- * Documentation: http://sparkleformation.github.io/sparkle_formation
128
- * User Documentation: http://sparkleformation.github.io/sparkle_formation/UserDocs/README.html
34
+ * Documentation: http://www.sparkleformation.io/docs/sparkle_formation
129
35
  * Repository: https://github.com/sparkleformation/sparkle_formation
130
36
  * IRC: Freenode @ #sparkleformation
@@ -146,9 +146,10 @@ class SparkleFormation
146
146
  end
147
147
 
148
148
  end
149
- SfnRegistry = Registry
150
-
151
149
  end
150
+
151
+ SfnRegistry = SparkleFormation::Registry
152
+
152
153
  ::Object.constants.each do |const|
153
154
  unless(self.const_defined?(const))
154
155
  next if const == :Config # prevent warning output
@@ -261,6 +262,9 @@ class SparkleFormation
261
262
  unless(data[:name])
262
263
  data[:name] = slim_path.tr('/', '__').sub(/\.(rb|json)$/, '')
263
264
  end
265
+ if(hash[data[:name]])
266
+ raise KeyError.new "Template name is already in use within pack! (`#{data[:name]}`)"
267
+ end
264
268
  hash[data[:name]] = data.merge(
265
269
  Smash.new(
266
270
  :type => :template,
@@ -281,7 +285,7 @@ class SparkleFormation
281
285
  # @raises [NameError, Error::NotFound]
282
286
  def get(type, name)
283
287
  unless(TYPES.keys.include?(type.to_s))
284
- raise NameError.new "Invalid type requested (#{type})! Valid types: #{TYPES.join(', ')}"
288
+ raise NameError.new "Invalid type requested (#{type})! Valid types: #{TYPES.keys.join(', ')}"
285
289
  end
286
290
  result = send(TYPES[type])[name]
287
291
  if(result.nil? && TYPES[type] == 'templates')
@@ -334,12 +338,17 @@ class SparkleFormation
334
338
  raw_data.each do |key, items|
335
339
  items.each do |item|
336
340
  if(item[:name])
337
- send(TYPES[key])[item.delete(:name)] = item
341
+ collection = send(TYPES[key])
342
+ name = item.delete(:name)
338
343
  else
339
344
  path = item[:block].source_location.first.sub('.rb', '').split(File::SEPARATOR)
340
345
  type, name = path.slice(path.size - 2, 2)
341
- send(type)[name] = item
346
+ collection = send(type)
347
+ end
348
+ if(collection[name])
349
+ raise KeyError.new "#{key.capitalize} name is already in use within pack! (`#{name}`)"
342
350
  end
351
+ collection[name] = item
343
352
  end
344
353
  end
345
354
  end
@@ -334,7 +334,7 @@ class SparkleFormation
334
334
  # @param args [Object] argument list for registry
335
335
  # @return [self]
336
336
  def registry!(name, *args)
337
- SparkleFormation::Registry.insert(name, self, *args)
337
+ SparkleFormation.registry(name, self, *args)
338
338
  end
339
339
 
340
340
  # Stack nesting helper method
@@ -187,6 +187,18 @@ class SparkleFormation
187
187
  end
188
188
  alias_method :dynamic_information, :dynamic_info
189
189
 
190
+ # Insert a dynamic into a context
191
+ #
192
+ # @param dynamic_name [String, Symbol] dynamic name
193
+ # @param struct [SparkleStruct] context for insertion
194
+ # @param args [Object] parameters for dynamic
195
+ # @return [SparkleStruct]
196
+ def registry(registry_name, struct, *args)
197
+ result = false
198
+ reg = struct._self.sparkle.get(:registry, registry_name)
199
+ struct.instance_exec(*args, &reg[:block])
200
+ end
201
+
190
202
  # Insert a dynamic into a context
191
203
  #
192
204
  # @param dynamic_name [String, Symbol] dynamic name
@@ -1,4 +1,4 @@
1
1
  class SparkleFormation
2
2
  # Current library version
3
- VERSION = Gem::Version.new('1.1.6')
3
+ VERSION = Gem::Version.new('1.1.8')
4
4
  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: 1.1.6
4
+ version: 1.1.8
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-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attribute_struct