Class: Xaases::Aws::Dynamodb

Inherits:
Object
  • Object
show all
Defined in:
lib/xaases/aws/dynamodb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *keys) ⇒ Dynamodb

Returns a new instance of Dynamodb.



5
6
7
8
# File 'lib/xaases/aws/dynamodb.rb', line 5

def initialize(name, *keys)
  @name = name
  @keys = keys
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/xaases/aws/dynamodb.rb', line 4

def keys
  @keys
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/xaases/aws/dynamodb.rb', line 4

def name
  @name
end

Instance Method Details

#attribute_definitionsObject



10
11
12
13
14
15
16
17
# File 'lib/xaases/aws/dynamodb.rb', line 10

def attribute_definitions
  keys.map do |key, type|
    {
      "AttributeName" => key,
      "AttributeType" => (type == 'integer' ? 'N' : 'S')
    }
  end
end

#key_schemaObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/xaases/aws/dynamodb.rb', line 19

def key_schema
  i = 0
  keys.map do |key, type|
    i += 1
    {
      "AttributeName" => key,
      "KeyType" => (i == 1 ? 'HASH' : 'RANGE')
    }
  end
end

#to_hashObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xaases/aws/dynamodb.rb', line 30

def to_hash
  {
    "Type" => 'AWS::DynamoDB::Table',
    "Properties" => {
      "TableName" => name,
      "AttributeDefinitions" => attribute_definitions,
      "KeySchema" => key_schema,
      "ProvisionedThroughput" => {
        "ReadCapacityUnits" => 1,
        "WriteCapacityUnits" => 1
      }
    }
  }
end