cloud_formation 0.1.2 → 0.1.3

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: 5c28700bca1d3dad061e12b10d3587e60e2248f1
4
- data.tar.gz: 2faf4c04795ecdcf492a00ebe4665aa9e51ef75a
3
+ metadata.gz: e28fac1fb5095b00790bf590942d272275cace0a
4
+ data.tar.gz: 618a1852d7398f4009b9415d7a47d2b8ef308b35
5
5
  SHA512:
6
- metadata.gz: 8b2174afbd62a8509242de4f1dd17c95e0fdf75e85dbb9a1d4f8990edeba4470bb2e2a65506b1cd39c252f4015e9119e86be15dabc9598aae99c6143571a4787
7
- data.tar.gz: 1adad111f96331fb195abfe6685dfd2f4001a8dc50aff8458917b4a1b20f62f311b6c7115c635748ec9ee10b30f253911c86138cb541b7b99c165c8e276b38bc
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 key_type_mapping type
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" => key_type_mapping(key[k]) }
66
+ { "AttributeName" => k.to_s, "AttributeType" => type_mapping(key[k]) }
56
67
  end
57
68
 
58
69
  end
@@ -1,3 +1,3 @@
1
1
  module CloudFormation
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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 test_basic
24
- expected = @table.serialize
25
- assert_equal load_fixture("dynamo_db/basic"), expected
26
- end
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.2
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-15 00:00:00.000000000 Z
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