chemtrail 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chemtrail/function.rb +20 -0
- data/lib/chemtrail/output.rb +29 -0
- data/lib/chemtrail/property_list.rb +8 -0
- data/lib/chemtrail/reference_presenter.rb +14 -0
- data/lib/chemtrail/resource.rb +25 -0
- data/lib/chemtrail/version.rb +1 -1
- data/lib/chemtrail.rb +4 -0
- data/spec/lib/chemtrail/function_spec.rb +36 -0
- data/spec/lib/chemtrail/output_spec.rb +36 -0
- data/spec/lib/chemtrail/property_list_spec.rb +25 -0
- data/spec/lib/chemtrail/reference_presenter_spec.rb +25 -1
- data/spec/lib/chemtrail/resource_spec.rb +23 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b55d85bd6bb36bc1f6b169a3806544b9df96db28
|
4
|
+
data.tar.gz: 1f2537d1b31d10f54e32d3d2391d64f774939ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27c03f23e82d4429bee7cac5ccb464e408ba7b6a6d7d146bfde9c46557785e677509c66757162317a31bbc55926b138ea075f1e513f3ab54fb54ad4f953362d5
|
7
|
+
data.tar.gz: 312879ef2f152e0b9a92eaf5f28bb874065749cb20ff2808e219421da935b77b7d1767663053eab9125c0e0061a89afdc50f5f13ed097ab8bd5b5a90dd9f2806
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Chemtrail::Function
|
2
|
+
attr_reader :name, :arguments
|
3
|
+
|
4
|
+
def initialize(name, *arguments)
|
5
|
+
@name = name
|
6
|
+
@arguments = arguments
|
7
|
+
end
|
8
|
+
|
9
|
+
def argument_list
|
10
|
+
@argument_list ||= arguments.map do |argument|
|
11
|
+
Chemtrail::ReferencePresenter.new(argument).to_parameter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
name => argument_list.count > 1 ? argument_list : argument_list.first || ""
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Chemtrail::Output
|
2
|
+
attr_reader :id, :value, :description
|
3
|
+
|
4
|
+
def initialize(id, value, description = nil)
|
5
|
+
@id = id
|
6
|
+
@value = value
|
7
|
+
@description = description
|
8
|
+
end
|
9
|
+
|
10
|
+
def value_parameter
|
11
|
+
Chemtrail::ReferencePresenter.new(value).to_parameter
|
12
|
+
end
|
13
|
+
|
14
|
+
def description_hash
|
15
|
+
if description.nil?
|
16
|
+
{}
|
17
|
+
else
|
18
|
+
{"Description" => description}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
{
|
24
|
+
id => {
|
25
|
+
"Value" => value_parameter
|
26
|
+
}.merge(description_hash)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
@@ -9,9 +9,23 @@ class Chemtrail::ReferencePresenter
|
|
9
9
|
argument.respond_to?(:to_reference)
|
10
10
|
end
|
11
11
|
|
12
|
+
def iterable?
|
13
|
+
argument.respond_to?(:each)
|
14
|
+
end
|
15
|
+
|
16
|
+
def hashlike?
|
17
|
+
argument.respond_to?(:to_hash)
|
18
|
+
end
|
19
|
+
|
12
20
|
def to_parameter
|
13
21
|
if reference?
|
14
22
|
argument.to_reference
|
23
|
+
elsif iterable?
|
24
|
+
if hashlike?
|
25
|
+
argument.reduce(argument) { |h, (k, v)| h[k] = self.class.new(v).to_parameter; h }
|
26
|
+
else
|
27
|
+
argument.map { |item| self.class.new(item).to_parameter }
|
28
|
+
end
|
15
29
|
else
|
16
30
|
argument
|
17
31
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Chemtrail::Resource
|
2
|
+
attr_reader :id, :type
|
3
|
+
|
4
|
+
def initialize(id, type)
|
5
|
+
@id = id
|
6
|
+
@type = type
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_reference
|
10
|
+
{ "Ref" => id }
|
11
|
+
end
|
12
|
+
|
13
|
+
def properties
|
14
|
+
@properties ||= Chemtrail::PropertyList.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
{
|
19
|
+
id => {
|
20
|
+
"Type" => type,
|
21
|
+
"Properties" => properties.to_hash
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
data/lib/chemtrail/version.rb
CHANGED
data/lib/chemtrail.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Chemtrail::Function do
|
4
|
+
let(:arguments) { [] }
|
5
|
+
|
6
|
+
subject(:function) { Chemtrail::Function.new("BrushTeeth", *arguments) }
|
7
|
+
|
8
|
+
its(:name) { should == "BrushTeeth" }
|
9
|
+
its(:arguments) { should be_empty }
|
10
|
+
|
11
|
+
context "when the function gets no arguments" do
|
12
|
+
its(:argument_list) { should be_empty }
|
13
|
+
its(:to_hash) { should == { "BrushTeeth" => "" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when the function gets a single argument" do
|
17
|
+
let(:arguments) { ["tasty"] }
|
18
|
+
|
19
|
+
its(:argument_list) { should == ["tasty"] }
|
20
|
+
its(:to_hash) { should == { "BrushTeeth" => "tasty" } }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when the function gets multiple arguments" do
|
24
|
+
let(:arguments) { ["orange", "juice"] }
|
25
|
+
|
26
|
+
its(:argument_list) { should == ["orange", "juice"] }
|
27
|
+
its(:to_hash) { should == { "BrushTeeth" => ["orange", "juice"] } }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the function has a reference argument" do
|
31
|
+
let(:arguments) { [double(:argument, to_reference: "flossing")] }
|
32
|
+
|
33
|
+
its(:argument_list) { should == ["flossing"] }
|
34
|
+
its(:to_hash) { should == { "BrushTeeth" => "flossing" } }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Chemtrail::Output do
|
4
|
+
let(:value) { "delicious" }
|
5
|
+
|
6
|
+
subject(:output) { Chemtrail::Output.new("chocolate", value) }
|
7
|
+
|
8
|
+
its(:id) { should == "chocolate" }
|
9
|
+
its(:value) { should == "delicious" }
|
10
|
+
|
11
|
+
context "when the value is a literal" do
|
12
|
+
its(:value_parameter) { should == "delicious" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when the value is a reference" do
|
16
|
+
let(:value) { double(:value, to_reference: "nom") }
|
17
|
+
|
18
|
+
its(:value_parameter) { should == "nom" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when no description is provided" do
|
22
|
+
its(:description) { should be_nil }
|
23
|
+
its(:description_hash) { should be_empty }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when a description is provided" do
|
27
|
+
subject(:output) { Chemtrail::Output.new("chocolate", "nast", "wat") }
|
28
|
+
|
29
|
+
its(:description) { should == "wat" }
|
30
|
+
its(:description_hash) { should == {"Description" => "wat"} }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_hash" do
|
34
|
+
its(:to_hash) { should == {"chocolate" => {"Value"=>"delicious"}} }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Chemtrail::PropertyList do
|
4
|
+
let(:fake_entry) { double(:entry, to_reference: "zuul") }
|
5
|
+
|
6
|
+
subject(:list) { Chemtrail::PropertyList.new }
|
7
|
+
|
8
|
+
context "when the list contains a literal" do
|
9
|
+
before { list[:ghostbusters] = "light's green, trap's clean" }
|
10
|
+
|
11
|
+
its(:to_hash) { should == {ghostbusters: "light's green, trap's clean"} }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when the list contains a reference" do
|
15
|
+
before { list[:ghostbusters] = fake_entry }
|
16
|
+
|
17
|
+
its(:to_hash) { should == {ghostbusters: "zuul"} }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the list contains a nested reference" do
|
21
|
+
before { list[:ghostbusters] = {gatekeeper: "zuul"} }
|
22
|
+
|
23
|
+
its(:to_hash) { should == {ghostbusters: {gatekeeper: "zuul"}} }
|
24
|
+
end
|
25
|
+
end
|
@@ -1,19 +1,43 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Chemtrail::ReferencePresenter do
|
4
|
+
let(:fake_reference) { double(:argument, to_reference: "reference") }
|
5
|
+
|
4
6
|
subject(:presenter) { Chemtrail::ReferencePresenter.new(argument) }
|
5
7
|
|
6
8
|
context "when the argument is a string literal" do
|
7
9
|
let(:argument) { "literal" }
|
8
10
|
|
9
11
|
it { should_not be_reference }
|
12
|
+
it { should_not be_iterable }
|
13
|
+
it { should_not be_hashlike }
|
10
14
|
its(:to_parameter) { should == "literal"}
|
11
15
|
end
|
12
16
|
|
13
17
|
context "when the argument can resolve into a reference" do
|
14
|
-
let(:argument) {
|
18
|
+
let(:argument) { fake_reference }
|
15
19
|
|
16
20
|
it { should be_reference }
|
21
|
+
it { should_not be_iterable }
|
22
|
+
it { should_not be_hashlike }
|
17
23
|
its(:to_parameter) { should == "reference" }
|
18
24
|
end
|
25
|
+
|
26
|
+
context "when the argument contains a nested reference" do
|
27
|
+
let(:argument) { [fake_reference] }
|
28
|
+
|
29
|
+
it { should_not be_reference }
|
30
|
+
it { should be_iterable }
|
31
|
+
it { should_not be_hashlike }
|
32
|
+
its(:to_parameter) { should == ["reference"] }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the argument contains a nested reference in a hash" do
|
36
|
+
let(:argument) { {"key" => fake_reference} }
|
37
|
+
|
38
|
+
it { should_not be_reference }
|
39
|
+
it { should be_iterable }
|
40
|
+
it { should be_hashlike }
|
41
|
+
its(:to_parameter) { should == {"key" => "reference"} }
|
42
|
+
end
|
19
43
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Chemtrail::Resource do
|
4
|
+
subject(:resource) { Chemtrail::Resource.new("toenails", "Gross") }
|
5
|
+
|
6
|
+
its(:id) { should == "toenails" }
|
7
|
+
its(:type) { should == "Gross" }
|
8
|
+
its(:to_reference) { should == { "Ref" => "toenails" } }
|
9
|
+
|
10
|
+
context "when there are no properties" do
|
11
|
+
its(:to_hash) { should have_key "toenails" }
|
12
|
+
specify { resource.to_hash["toenails"].should include("Type" => "Gross") }
|
13
|
+
specify { resource.to_hash["toenails"].should include("Properties" => {}) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when there is a property" do
|
17
|
+
let(:hash) { resource.to_hash["toenails"] }
|
18
|
+
|
19
|
+
before { resource.properties["UserDingus"] = "whatever" }
|
20
|
+
|
21
|
+
specify { hash["Properties"].should include("UserDingus" => "whatever") }
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chemtrail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doc Ritezel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -99,15 +99,23 @@ files:
|
|
99
99
|
- chemtrail.gemspec
|
100
100
|
- lib/chemtrail.rb
|
101
101
|
- lib/chemtrail/declaration.rb
|
102
|
+
- lib/chemtrail/function.rb
|
102
103
|
- lib/chemtrail/mapping.rb
|
104
|
+
- lib/chemtrail/output.rb
|
105
|
+
- lib/chemtrail/property_list.rb
|
103
106
|
- lib/chemtrail/reference_presenter.rb
|
107
|
+
- lib/chemtrail/resource.rb
|
104
108
|
- lib/chemtrail/section.rb
|
105
109
|
- lib/chemtrail/template.rb
|
106
110
|
- lib/chemtrail/version.rb
|
107
111
|
- script/ci.sh
|
108
112
|
- spec/lib/chemtrail/declaration_spec.rb
|
113
|
+
- spec/lib/chemtrail/function_spec.rb
|
109
114
|
- spec/lib/chemtrail/mapping_spec.rb
|
115
|
+
- spec/lib/chemtrail/output_spec.rb
|
116
|
+
- spec/lib/chemtrail/property_list_spec.rb
|
110
117
|
- spec/lib/chemtrail/reference_presenter_spec.rb
|
118
|
+
- spec/lib/chemtrail/resource_spec.rb
|
111
119
|
- spec/lib/chemtrail/section_spec.rb
|
112
120
|
- spec/lib/chemtrail/template_spec.rb
|
113
121
|
- spec/spec_helper.rb
|
@@ -137,8 +145,12 @@ specification_version: 4
|
|
137
145
|
summary: Build, create and maintain your CloudFormation stack
|
138
146
|
test_files:
|
139
147
|
- spec/lib/chemtrail/declaration_spec.rb
|
148
|
+
- spec/lib/chemtrail/function_spec.rb
|
140
149
|
- spec/lib/chemtrail/mapping_spec.rb
|
150
|
+
- spec/lib/chemtrail/output_spec.rb
|
151
|
+
- spec/lib/chemtrail/property_list_spec.rb
|
141
152
|
- spec/lib/chemtrail/reference_presenter_spec.rb
|
153
|
+
- spec/lib/chemtrail/resource_spec.rb
|
142
154
|
- spec/lib/chemtrail/section_spec.rb
|
143
155
|
- spec/lib/chemtrail/template_spec.rb
|
144
156
|
- spec/spec_helper.rb
|