rubycfn 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +13 -13
- data/README.md +1 -1
- data/lib/rubycfn/version.rb +1 -1
- data/lib/rubycfn.rb +37 -15
- data/spec/lib/rubycfn_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d733dda0a2fd9505dc4e84d6d65670f3acbe1322
|
4
|
+
data.tar.gz: 782fc35dc9375763e592671ab952fa18679f80a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68087c6444b29e2d5f26871dcdf8e805b3996481066c93f4a444cbe161d85d8372caccf980ad6b01496e360fc0d69fa9f5266c3ba22a6efa6bdff5809c3ad17b
|
7
|
+
data.tar.gz: 2d3780fb60ca99005a14248dced1e4f9041fda32efd2541a4ab921f14116e183c07bd0ef0cd346b561c697d2851f7bbd12594fa9b857c645b6d9e313c6e21ec6
|
data/.rubocop.yml
CHANGED
@@ -51,7 +51,7 @@ Metrics/ModuleLength:
|
|
51
51
|
Max: 500
|
52
52
|
|
53
53
|
Metrics/MethodLength:
|
54
|
-
Max:
|
54
|
+
Max: 100
|
55
55
|
|
56
56
|
Metrics/BlockLength:
|
57
57
|
Max: 500
|
@@ -59,6 +59,9 @@ Metrics/BlockLength:
|
|
59
59
|
Performance/Casecmp:
|
60
60
|
Enabled: false
|
61
61
|
|
62
|
+
Style/RedundantSelf:
|
63
|
+
Enabled: false
|
64
|
+
|
62
65
|
Style/DoubleNegation:
|
63
66
|
Enabled: false
|
64
67
|
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
All notable changes to Rubycfn will be documented in this file.
|
3
3
|
This project uses [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
-
## 0.
|
5
|
+
## 0.4.1 (Next Release)
|
6
|
+
|
7
|
+
## 0.4.0
|
8
|
+
|
9
|
+
* Added resource elements `update_policy`, `update_replace_policy`, `metadata`, `depends_on`, `deletion_policy` and `creation_policy`.
|
10
|
+
* This release breaks the `r.meta` property. -- [@dennisvink][@dennisvink]
|
6
11
|
|
7
12
|
## 0.3.9
|
8
13
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubycfn (0.
|
4
|
+
rubycfn (0.4.0)
|
5
5
|
activesupport (~> 5.1.5)
|
6
6
|
dotenv (~> 2.4.0)
|
7
7
|
json (~> 2.1.0)
|
@@ -16,20 +16,20 @@ GEM
|
|
16
16
|
i18n (>= 0.7, < 2)
|
17
17
|
minitest (~> 5.1)
|
18
18
|
tzinfo (~> 1.1)
|
19
|
-
addressable (2.
|
20
|
-
public_suffix (>= 2.0.2, <
|
19
|
+
addressable (2.7.0)
|
20
|
+
public_suffix (>= 2.0.2, < 5.0)
|
21
21
|
awesome_print (1.8.0)
|
22
22
|
coderay (1.1.2)
|
23
23
|
concurrent-ruby (1.1.5)
|
24
24
|
diff-lcs (1.3)
|
25
|
-
docile (1.3.
|
25
|
+
docile (1.3.2)
|
26
26
|
dotenv (2.4.0)
|
27
27
|
equatable (0.6.1)
|
28
|
-
ffi (1.
|
28
|
+
ffi (1.11.1)
|
29
29
|
formatador (0.2.5)
|
30
30
|
given_core (3.8.0)
|
31
31
|
sorcerer (>= 0.3.7)
|
32
|
-
guard (2.15.
|
32
|
+
guard (2.15.1)
|
33
33
|
formatador (>= 0.2.4)
|
34
34
|
listen (>= 2.7, < 4.0)
|
35
35
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
neatjson (0.8.4)
|
59
59
|
necromancer (0.4.0)
|
60
60
|
nenv (0.3.0)
|
61
|
-
notiffany (0.1.
|
61
|
+
notiffany (0.1.3)
|
62
62
|
nenv (~> 0.1)
|
63
63
|
shellany (~> 0.0)
|
64
64
|
pastel (0.7.3)
|
@@ -67,7 +67,7 @@ GEM
|
|
67
67
|
pry (0.12.2)
|
68
68
|
coderay (~> 1.1.0)
|
69
69
|
method_source (~> 0.9.0)
|
70
|
-
public_suffix (
|
70
|
+
public_suffix (4.0.1)
|
71
71
|
rake (10.5.0)
|
72
72
|
rb-fsevent (0.10.3)
|
73
73
|
rb-inotify (0.10.0)
|
@@ -76,9 +76,9 @@ GEM
|
|
76
76
|
rspec-core (~> 3.8.0)
|
77
77
|
rspec-expectations (~> 3.8.0)
|
78
78
|
rspec-mocks (~> 3.8.0)
|
79
|
-
rspec-core (3.8.
|
79
|
+
rspec-core (3.8.2)
|
80
80
|
rspec-support (~> 3.8.0)
|
81
|
-
rspec-expectations (3.8.
|
81
|
+
rspec-expectations (3.8.4)
|
82
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
83
83
|
rspec-support (~> 3.8.0)
|
84
84
|
rspec-given (3.8.0)
|
@@ -87,15 +87,15 @@ GEM
|
|
87
87
|
rspec-its (1.3.0)
|
88
88
|
rspec-core (>= 3.0.0)
|
89
89
|
rspec-expectations (>= 3.0.0)
|
90
|
-
rspec-mocks (3.8.
|
90
|
+
rspec-mocks (3.8.1)
|
91
91
|
diff-lcs (>= 1.2.0, < 2.0)
|
92
92
|
rspec-support (~> 3.8.0)
|
93
|
-
rspec-support (3.8.
|
93
|
+
rspec-support (3.8.2)
|
94
94
|
rspec_junit_formatter (0.4.1)
|
95
95
|
rspec-core (>= 2, < 4, != 2.12.0)
|
96
96
|
ruby_dep (1.5.0)
|
97
97
|
shellany (0.0.1)
|
98
|
-
simplecov (0.
|
98
|
+
simplecov (0.17.1)
|
99
99
|
docile (~> 1.1)
|
100
100
|
json (>= 1.8, < 3)
|
101
101
|
simplecov-html (~> 0.10.0)
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ __________ ____ __________________.___._________ _____________________
|
|
61
61
|
| _/ | /| | _// | |/ \ \/ | __) | | _/
|
62
62
|
| | \ | / | | \\____ |\ \____| \ | | \
|
63
63
|
|____|_ /______/ |______ // ______| \______ /\___ / |______ /
|
64
|
-
\/ \/ \/ \/ \/ \/ [v0.
|
64
|
+
\/ \/ \/ \/ \/ \/ [v0.4.0]
|
65
65
|
Project name? example
|
66
66
|
Account ID? 1234567890
|
67
67
|
Select region EU (Frankfurt)
|
data/lib/rubycfn/version.rb
CHANGED
data/lib/rubycfn.rb
CHANGED
@@ -4,13 +4,11 @@ require "json"
|
|
4
4
|
require "neatjson"
|
5
5
|
require "rubycfn/version"
|
6
6
|
|
7
|
-
@depends_on = []
|
8
7
|
@description = ""
|
9
8
|
@transform = ""
|
10
9
|
@outputs = {}
|
11
10
|
@parameters = {}
|
12
11
|
@properties = {}
|
13
|
-
@metadata = {}
|
14
12
|
@mappings = {}
|
15
13
|
@conditions = {}
|
16
14
|
@aws_resources = {}
|
@@ -21,6 +19,11 @@ require "rubycfn/version"
|
|
21
19
|
|
22
20
|
# Monkey patching
|
23
21
|
class Symbol
|
22
|
+
def cfnize
|
23
|
+
return self.to_s if self.to_s !~ /_/ && self.to_s =~ /[A-Z]+.*/
|
24
|
+
to_s.split("_").map(&:capitalize).join
|
25
|
+
end
|
26
|
+
|
24
27
|
def ref(attr = nil)
|
25
28
|
unless attr
|
26
29
|
return { Ref: to_s.split("_").map(&:capitalize).join }
|
@@ -192,14 +195,12 @@ class Array
|
|
192
195
|
end
|
193
196
|
|
194
197
|
class ::Hash
|
195
|
-
# rubocop:disable Style/RedundantSelf
|
196
198
|
# rubocop:disable Style/CaseEquality
|
197
199
|
# rubocop:disable Lint/UnusedBlockArgument
|
198
200
|
def deep_merge(second)
|
199
201
|
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
|
200
202
|
self.merge(second.to_h, &merger)
|
201
203
|
end
|
202
|
-
# rubocop:enable Style/RedundantSelf
|
203
204
|
# rubocop:enable Style/CaseEquality
|
204
205
|
# rubocop:enable Lint/UnusedBlockArgument
|
205
206
|
|
@@ -366,12 +367,6 @@ module Rubycfn
|
|
366
367
|
end
|
367
368
|
# rubocop:enable Lint/UnusedMethodArgument
|
368
369
|
|
369
|
-
def self.meta(name, _index = 0, &block)
|
370
|
-
name = name.class == Symbol ? TOPLEVEL_BINDING.eval("'#{name}'.cfnize") : TOPLEVEL_BINDING.eval("'#{name}'")
|
371
|
-
res = { "#{name}": yield(block) }
|
372
|
-
TOPLEVEL_BINDING.eval("@metadata = @metadata.deep_merge(#{res})")
|
373
|
-
end
|
374
|
-
|
375
370
|
def self.property(name, _index = 0, &block)
|
376
371
|
name = name.class == Symbol ? TOPLEVEL_BINDING.eval("'#{name}'.cfnize") : TOPLEVEL_BINDING.eval("'#{name}'")
|
377
372
|
res = { "#{name}": yield(block) }
|
@@ -403,21 +398,48 @@ module Rubycfn
|
|
403
398
|
TOPLEVEL_BINDING.eval("@resource_name = ''")
|
404
399
|
end
|
405
400
|
|
401
|
+
# Transform depends_on based on input class
|
402
|
+
unless arguments[:depends_on].nil? && TOPLEVEL_BINDING.eval("@depends_on").nil?
|
403
|
+
|
404
|
+
# Initialize arguments[:depends_on] if it is nil
|
405
|
+
arguments[:depends_on] = arguments[:depends_on].nil? && [] || arguments[:depends_on]
|
406
|
+
|
407
|
+
# If the argument is a string, create an array out of it with a single element
|
408
|
+
arguments[:depends_on] = arguments[:depends_on].class == Array && arguments[:depends_on] || [arguments[:depends_on]]
|
409
|
+
|
410
|
+
# `r.depends_on` is used to amend depends_on with resources with dynamic names
|
411
|
+
# Here we add them to arguments[:depends_on]
|
412
|
+
to_amend = TOPLEVEL_BINDING.eval("@depends_on")
|
413
|
+
unless to_amend.nil?
|
414
|
+
to_amend = to_amend.class == String && [to_amend] || to_amend
|
415
|
+
to_amend.each do |amend|
|
416
|
+
arguments[:depends_on].push(amend)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
TOPLEVEL_BINDING.eval("@depends_on = []")
|
420
|
+
|
421
|
+
# Finally, we render the DependsOn array
|
422
|
+
arguments[:depends_on].map! { |resource| resource.class == String && resource.to_s || resource.to_s.split("_").map(&:capitalize).join }
|
423
|
+
end
|
424
|
+
|
406
425
|
res = {
|
407
426
|
"#{name.to_s}#{i.zero? ? "" : resource_postpend}": {
|
408
|
-
DependsOn: TOPLEVEL_BINDING.eval("@depends_on"),
|
409
|
-
Metadata: TOPLEVEL_BINDING.eval("@metadata"),
|
410
427
|
Properties: TOPLEVEL_BINDING.eval("@properties"),
|
411
428
|
Type: arguments[:type],
|
412
429
|
Condition: arguments[:condition],
|
413
|
-
UpdatePolicy: arguments[:update_policy]
|
430
|
+
UpdatePolicy: arguments[:update_policy],
|
431
|
+
UpdateReplacePolicy: arguments[:update_replace_policy],
|
432
|
+
Metadata: arguments[:metadata],
|
433
|
+
DependsOn: arguments[:depends_on],
|
434
|
+
DeletionPolicy: arguments[:deletion_policy],
|
435
|
+
CreationPolicy: arguments[:creation_policy]
|
414
436
|
}
|
415
437
|
}
|
438
|
+
arguments[:depends_on] = []
|
416
439
|
TOPLEVEL_BINDING.eval("@aws_resources = @aws_resources.deep_merge(#{res})")
|
417
440
|
end
|
418
441
|
TOPLEVEL_BINDING.eval("@depends_on = []")
|
419
442
|
TOPLEVEL_BINDING.eval("@properties = {}")
|
420
|
-
TOPLEVEL_BINDING.eval("@metadata = {}")
|
421
443
|
end
|
422
444
|
end
|
423
445
|
|
@@ -439,7 +461,7 @@ module Rubycfn
|
|
439
461
|
skeleton[:Conditions] = sort_json(TOPLEVEL_BINDING.eval("@conditions"))
|
440
462
|
skeleton[:Resources] = sort_json(TOPLEVEL_BINDING.eval("@aws_resources"))
|
441
463
|
skeleton[:Outputs] = sort_json(TOPLEVEL_BINDING.eval("@outputs"))
|
442
|
-
TOPLEVEL_BINDING.eval("@variables = @aws_resources = @outputs = @
|
464
|
+
TOPLEVEL_BINDING.eval("@variables = @aws_resources = @outputs = @properties = @mappings = @parameters = {}")
|
443
465
|
TOPLEVEL_BINDING.eval("@depends_on = []")
|
444
466
|
TOPLEVEL_BINDING.eval("@description = ''")
|
445
467
|
TOPLEVEL_BINDING.eval("@transform = ''")
|
data/spec/lib/rubycfn_spec.rb
CHANGED
@@ -13,6 +13,7 @@ describe Rubycfn do
|
|
13
13
|
description "RSpec Test Stack"
|
14
14
|
|
15
15
|
resource :rspec_resource_name,
|
16
|
+
depends_on: [:foo_bar,"fooBar"],
|
16
17
|
type: "Rspec::Test",
|
17
18
|
update_policy: {
|
18
19
|
"AutoScalingReplacingUpdate": {
|
@@ -20,6 +21,7 @@ describe Rubycfn do
|
|
20
21
|
}
|
21
22
|
},
|
22
23
|
amount: 2 do |r|
|
24
|
+
r.depends_on [ "barFoo", :bar_foo ]
|
23
25
|
r.property(:name) { "RSpec" }
|
24
26
|
end
|
25
27
|
end
|
@@ -57,10 +59,18 @@ describe Rubycfn do
|
|
57
59
|
let(:resource) { resources["RspecResourceName"] }
|
58
60
|
subject { resource }
|
59
61
|
|
62
|
+
it { should have_key "DependsOn" }
|
60
63
|
it { should have_key "Type" }
|
61
64
|
it { should have_key "Properties" }
|
62
65
|
it { should have_key "UpdatePolicy"}
|
63
66
|
|
67
|
+
context "depends_on is rendered correctly" do
|
68
|
+
let(:depends_on) { resource["DependsOn"] }
|
69
|
+
subject { depends_on }
|
70
|
+
|
71
|
+
it { should eq ["FooBar", "fooBar", "barFoo", "BarFoo"] }
|
72
|
+
end
|
73
|
+
|
64
74
|
context "resource type is correct" do
|
65
75
|
let(:type) { resource["Type"] }
|
66
76
|
subject { type }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycfn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Vink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|