Class: Dyna::DSL::DynamoDB::Table
- Inherits:
-
Object
- Object
- Dyna::DSL::DynamoDB::Table
show all
- Includes:
- TemplateHelper
- Defined in:
- lib/dyna/dsl/table.rb
Defined Under Namespace
Classes: GlobalSecondaryIndex, LocalSecondaryIndex
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#attribute_definition(attribute_name:, attribute_type:) ⇒ Object
-
#billing_mode(billing_mode) ⇒ Object
-
#global_secondary_index(index_name, &block) ⇒ Object
-
#initialize(context, table_name, &block) ⇒ Table
constructor
-
#key_schema(hash:, range: nil) ⇒ Object
-
#local_secondary_index(index_name, &block) ⇒ Object
-
#provisioned_throughput(read_capacity_units:, write_capacity_units:) ⇒ Object
-
#scalable_target(scalable_dimension:, min_capacity:, max_capacity:) ⇒ Object
-
#scaling_policy(scalable_dimension:, target_tracking_scaling_policy_configuration:) ⇒ Object
-
#stream_specification(stream_enabled:, stream_view_type: nil) ⇒ Object
-
#time_to_live_specification(enabled:, attribute_name:) ⇒ Object
#context, #include_template
Constructor Details
#initialize(context, table_name, &block) ⇒ Table
Returns a new instance of Table.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/dyna/dsl/table.rb', line 8
def initialize(context, table_name, &block)
@table_name = table_name
@context = context
@result = Hashie::Mash.new({
:table_name => table_name,
:scalable_targets => [],
:scaling_policies => [],
:time_to_live_specification => {
enabled: false,
attribute_name: nil,
}
})
instance_eval(&block)
end
|
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
6
7
8
|
# File 'lib/dyna/dsl/table.rb', line 6
def result
@result
end
|
Instance Method Details
#attribute_definition(attribute_name:, attribute_type:) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/dyna/dsl/table.rb', line 38
def attribute_definition(attribute_name:, attribute_type:)
@result.attribute_definitions ||= []
@result.attribute_definitions << {
attribute_name: attribute_name,
attribute_type: attribute_type,
}
end
|
#billing_mode(billing_mode) ⇒ Object
78
79
80
|
# File 'lib/dyna/dsl/table.rb', line 78
def billing_mode(billing_mode)
@result.billing_mode = billing_mode
end
|
#global_secondary_index(index_name, &block) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/dyna/dsl/table.rb', line 69
def global_secondary_index(index_name, &block)
@result.global_secondary_indexes ||= []
index = GlobalSecondaryIndex.new
index.instance_eval(&block)
@result.global_secondary_indexes << {
index_name: index_name,
}.merge(index.result.symbolize_keys)
end
|
#key_schema(hash:, range: nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dyna/dsl/table.rb', line 24
def key_schema(hash:, range: nil)
@result.key_schema = [{
attribute_name: hash,
key_type: 'HASH',
}]
if range
@result.key_schema << {
attribute_name: range,
key_type: 'RANGE',
}
end
end
|
#local_secondary_index(index_name, &block) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/dyna/dsl/table.rb', line 60
def local_secondary_index(index_name, &block)
@result.local_secondary_indexes ||= []
index = LocalSecondaryIndex.new
index.instance_eval(&block)
@result.local_secondary_indexes << {
index_name: index_name,
}.merge(index.result.symbolize_keys)
end
|
#provisioned_throughput(read_capacity_units:, write_capacity_units:) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/dyna/dsl/table.rb', line 46
def provisioned_throughput(read_capacity_units:, write_capacity_units:)
@result.provisioned_throughput = {
read_capacity_units: read_capacity_units,
write_capacity_units: write_capacity_units,
}
end
|
#scalable_target(scalable_dimension:, min_capacity:, max_capacity:) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/dyna/dsl/table.rb', line 82
def scalable_target(scalable_dimension:, min_capacity:, max_capacity:)
@result.scalable_targets << {
service_namespace: 'dynamodb',
scalable_dimension: scalable_dimension,
resource_id: "table/#{@result.table_name}",
min_capacity: min_capacity,
max_capacity: max_capacity,
}
end
|
#scaling_policy(scalable_dimension:, target_tracking_scaling_policy_configuration:) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/dyna/dsl/table.rb', line 92
def scaling_policy(scalable_dimension:, target_tracking_scaling_policy_configuration:)
predefined_metric_type = 'DynamoDBWriteCapacityUtilization'
if scalable_dimension == 'dynamodb:table:ReadCapacityUnits'
predefined_metric_type = 'DynamoDBReadCapacityUtilization'
end
@result.scaling_policies << {
policy_name: "#{predefined_metric_type}:table/#{@result.table_name}",
policy_type: 'TargetTrackingScaling',
resource_id: "table/#{@result.table_name}",
scalable_dimension: scalable_dimension,
service_namespace: 'dynamodb',
target_tracking_scaling_policy_configuration: target_tracking_scaling_policy_configuration.merge(predefined_metric_specification: {predefined_metric_type: predefined_metric_type}),
}
end
|
#stream_specification(stream_enabled:, stream_view_type: nil) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/dyna/dsl/table.rb', line 53
def stream_specification(stream_enabled:, stream_view_type: nil)
@result.stream_specification = {
stream_enabled: stream_enabled,
stream_view_type: stream_view_type,
}
end
|
#time_to_live_specification(enabled:, attribute_name:) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/dyna/dsl/table.rb', line 107
def time_to_live_specification(enabled:, attribute_name:)
@result.time_to_live_specification = {
enabled: enabled,
attribute_name: attribute_name,
}
end
|