Class: Dynamoid::AdapterPlugin::AwsSdkV3::CreateTable
- Inherits:
-
Object
- Object
- Dynamoid::AdapterPlugin::AwsSdkV3::CreateTable
- Defined in:
- lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(client, table_name, key, options) ⇒ CreateTable
constructor
A new instance of CreateTable.
Constructor Details
#initialize(client, table_name, key, options) ⇒ CreateTable
Returns a new instance of CreateTable.
12 13 14 15 16 17 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 12 def initialize(client, table_name, key, ) @client = client @table_name = table_name @key = key @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 10 def client @client end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 10 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 10 def @options end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 10 def table_name @table_name end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb', line 19 def call billing_mode = [:billing_mode] read_capacity = [:read_capacity] || Dynamoid::Config.read_capacity write_capacity = [:write_capacity] || Dynamoid::Config.write_capacity secondary_indexes = .slice( :local_secondary_indexes, :global_secondary_indexes ) ls_indexes = [:local_secondary_indexes] gs_indexes = [:global_secondary_indexes] key_schema = { hash_key_schema: { key => [:hash_key_type] || :string }, range_key_schema: [:range_key] } attribute_definitions = build_all_attribute_definitions( key_schema, secondary_indexes ) key_schema = aws_key_schema( key_schema[:hash_key_schema], key_schema[:range_key_schema] ) client_opts = { table_name: table_name, key_schema: key_schema, attribute_definitions: attribute_definitions } if billing_mode == :on_demand client_opts[:billing_mode] = 'PAY_PER_REQUEST' else client_opts[:billing_mode] = 'PROVISIONED' client_opts[:provisioned_throughput] = { read_capacity_units: read_capacity, write_capacity_units: write_capacity } end if ls_indexes.present? client_opts[:local_secondary_indexes] = ls_indexes.map do |index| index_to_aws_hash(index) end end if gs_indexes.present? client_opts[:global_secondary_indexes] = gs_indexes.map do |index| index_to_aws_hash(index) end end resp = client.create_table(client_opts) [:sync] = true if (!.key?(:sync) && ls_indexes.present?) || gs_indexes.present? if [:sync] status = PARSE_TABLE_STATUS.call(resp, :table_description) if status == TABLE_STATUSES[:creating] UntilPastTableStatus.new(client, table_name, :creating).call end end # Response to original create_table, which, if options[:sync] # may have an outdated table_description.table_status of "CREATING" resp end |