cloud_formation 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloud_formation/dynamo_db.rb +13 -2
- data/lib/cloud_formation/version.rb +1 -1
- data/test/dynamo_db_test.rb +16 -4
- data/test/templates/dynamo_db/add_attributes.json +33 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e28fac1fb5095b00790bf590942d272275cace0a
|
4
|
+
data.tar.gz: 618a1852d7398f4009b9415d7a47d2b8ef308b35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd96b5b1052c3dbb4d619ffc1c65d1fc19cc16c4042ae070499bc152f1538b742ae308806ef3b676fbcad1f85e0d6b06b4352080e898139d5451fa3af306b2e8
|
7
|
+
data.tar.gz: 259f215e6b17f3189f38b1ec4554891a6f17260cbe2d0d08c7b86472839ee0f906c2b574a61111bbc83be57cbc52a897d4dd5ea6ccbdfc8c985422916344ff85
|
@@ -19,6 +19,12 @@ module CloudFormation
|
|
19
19
|
class Table < Base
|
20
20
|
attribute_list :name, :read_capacity_units, :write_capacity_units, :hash_key, :range_key
|
21
21
|
|
22
|
+
attr_accessor :attribute_definitions
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@attribute_definitions = []
|
26
|
+
end
|
27
|
+
|
22
28
|
def serialize
|
23
29
|
properties = {
|
24
30
|
"Type" => "AWS::DynamoDB::Table",
|
@@ -30,12 +36,17 @@ module CloudFormation
|
|
30
36
|
}
|
31
37
|
}
|
32
38
|
properties["Properties"].merge! add_key_schemas
|
39
|
+
properties["Properties"]["AttributeDefinitions"] = @attribute_definitions unless @attribute_definitions.empty?
|
33
40
|
properties
|
34
41
|
end
|
35
42
|
|
43
|
+
def add_attribute attr_name, attr_value
|
44
|
+
@attribute_definitions << { "AttributeName" => attr_name.to_s, "AttributeType" => type_mapping(attr_value) }
|
45
|
+
end
|
46
|
+
|
36
47
|
private
|
37
48
|
|
38
|
-
def
|
49
|
+
def type_mapping type
|
39
50
|
case type
|
40
51
|
when :string then "S"
|
41
52
|
when :number then "N"
|
@@ -52,7 +63,7 @@ module CloudFormation
|
|
52
63
|
|
53
64
|
def add_key_schema_for key
|
54
65
|
k = key.keys.first
|
55
|
-
{ "AttributeName" => k.to_s, "AttributeType" =>
|
66
|
+
{ "AttributeName" => k.to_s, "AttributeType" => type_mapping(key[k]) }
|
56
67
|
end
|
57
68
|
|
58
69
|
end
|
data/test/dynamo_db_test.rb
CHANGED
@@ -6,6 +6,11 @@ class DynamoDBTest < Minitest::Test
|
|
6
6
|
@table = build_dynamo_table_instance
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_basic
|
10
|
+
expected = @table.serialize
|
11
|
+
assert_equal load_fixture("dynamo_db/basic"), expected
|
12
|
+
end
|
13
|
+
|
9
14
|
def test_build_table_should_return_table_class
|
10
15
|
dynamo_db = CloudFormation::DynamoDB.new
|
11
16
|
table = build_dynamo_table_instance
|
@@ -20,9 +25,16 @@ class DynamoDBTest < Minitest::Test
|
|
20
25
|
assert_equal 1, dynamo_db.tables.length
|
21
26
|
end
|
22
27
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
def test_add_attribute_should_generate_attribute_definition_schema
|
29
|
+
dynamo_db = CloudFormation::DynamoDB.new
|
30
|
+
|
31
|
+
table = build_dynamo_table_instance
|
27
32
|
|
33
|
+
table.add_attribute :first_name, :string
|
34
|
+
table.add_attribute :last_name, :string
|
35
|
+
table.add_attribute :age, :number
|
36
|
+
|
37
|
+
assert_equal table.serialize, load_fixture('dynamo_db/add_attributes')
|
38
|
+
|
39
|
+
end
|
28
40
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"Type": "AWS::DynamoDB::Table",
|
3
|
+
"Properties": {
|
4
|
+
"ProvisionedThroughput": {
|
5
|
+
"WriteCapacityUnits": "5",
|
6
|
+
"ReadCapacityUnits": "10"
|
7
|
+
},
|
8
|
+
"KeySchema": {
|
9
|
+
"RangeKeyElement": {
|
10
|
+
"AttributeName": "column_two_id",
|
11
|
+
"AttributeType": "N"
|
12
|
+
},
|
13
|
+
"HashKeyElement": {
|
14
|
+
"AttributeName": "column_one_id",
|
15
|
+
"AttributeType": "N"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"AttributeDefinitions": [
|
19
|
+
{
|
20
|
+
"AttributeName": "first_name",
|
21
|
+
"AttributeType": "S"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"AttributeName": "last_name",
|
25
|
+
"AttributeType": "S"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"AttributeName": "age",
|
29
|
+
"AttributeType": "N"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_formation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- test/dynamo_db_test.rb
|
61
61
|
- test/factories/factory_helpers.rb
|
62
62
|
- test/template_test.rb
|
63
|
+
- test/templates/dynamo_db/add_attributes.json
|
63
64
|
- test/templates/dynamo_db/basic.json
|
64
65
|
- test/templates/template/adding_multiple_resources.json
|
65
66
|
- test/templates/template/adding_single_resource.json
|
@@ -94,6 +95,7 @@ test_files:
|
|
94
95
|
- test/dynamo_db_test.rb
|
95
96
|
- test/factories/factory_helpers.rb
|
96
97
|
- test/template_test.rb
|
98
|
+
- test/templates/dynamo_db/add_attributes.json
|
97
99
|
- test/templates/dynamo_db/basic.json
|
98
100
|
- test/templates/template/adding_multiple_resources.json
|
99
101
|
- test/templates/template/adding_single_resource.json
|