Class: Dynomite::Migration::Dsl::Index::Gsi
- Inherits:
-
Base
- Object
- Base
- Dynomite::Migration::Dsl::Index::Gsi
show all
- Defined in:
- lib/dynomite/migration/dsl/index/gsi.rb
Constant Summary
Constants included
from Types
Types::TYPE_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#conventional_index_name, #get_attribute_name, #get_attribute_type, #partition_key_attribute_name, #partition_key_attribute_type, #sort_key_attribute_name, #sort_key_attribute_type
Methods included from Types
#type_map
Constructor Details
#initialize(action, attrs) ⇒ Gsi
Returns a new instance of Gsi.
4
5
6
7
8
9
10
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 4
def initialize(action, attrs)
@action = action
@params = attrs.dup
@partition_key = @params.delete(:partition_key) || @params.delete(:hash_key) @sort_key = @params.delete(:sort_key) || @params.delete(:range_key) end
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3
4
5
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 3
def action
@action
end
|
#attrs ⇒ Object
Returns the value of attribute attrs.
3
4
5
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 3
def attrs
@attrs
end
|
Instance Method Details
#attribute_definitions ⇒ Object
41
42
43
44
45
46
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 41
def attribute_definitions
definitions = []
definitions << {attribute_name: partition_key_attribute_name, attribute_type: partition_key_attribute_type} unless @partition_key.blank?
definitions << {attribute_name: sort_key_attribute_name, attribute_type: sort_key_attribute_type} unless @sort_key.blank?
definitions
end
|
#normalize_provisioned_throughput(value) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 48
def normalize_provisioned_throughput(value)
if value.is_a?(Hash)
value
else
{
read_capacity_units: value,
write_capacity_units: value,
}
end
end
|
#params ⇒ Object
12
13
14
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 12
def params
send("params_#{@action}")
end
|
#params_create ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 17
def params_create
@params[:key_schema] ||= []
@params[:key_schema].unshift(attribute_name: partition_key_attribute_name, key_type: "HASH") unless @partition_key.blank?
@params[:key_schema] << {attribute_name: sort_key_attribute_name, key_type: "RANGE"} unless @sort_key.blank?
@params[:index_name] ||= conventional_index_name
@params[:projection] ||= {projection_type: "ALL"}
@params[:provisioned_throughput] = normalize_provisioned_throughput(@params[:provisioned_throughput]) if @params[:provisioned_throughput]
@params
end
|
#params_delete ⇒ Object
36
37
38
39
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 36
def params_delete
@params[:index_name] ||= conventional_index_name
@params
end
|
#params_update ⇒ Object
30
31
32
33
34
|
# File 'lib/dynomite/migration/dsl/index/gsi.rb', line 30
def params_update
@params[:index_name] ||= conventional_index_name
@params[:provisioned_throughput] = normalize_provisioned_throughput(@params[:provisioned_throughput]) if @params[:provisioned_throughput]
@params
end
|