class Dynamocli::AWS::Table

Constants

DELETION_IN_PROCESSING_KEY
DYNAMODB

Attributes

dynamodb[R]
schema[R]
table_name[R]
table_on_aws[R]

Public Class Methods

new(table_name:, table_on_aws:, dynamodb: nil) click to toggle source
# File lib/dynamocli/aws/table.rb, line 13
def initialize(table_name:, table_on_aws:, dynamodb: nil)
  @table_name = table_name
  @table_on_aws = table_on_aws
  @dynamodb = dynamodb || DYNAMODB.new

  set_schema_before_we_delete_the_table
end

Public Instance Methods

deleting?() click to toggle source
# File lib/dynamocli/aws/table.rb, line 21
def deleting?
  status == DELETION_IN_PROCESSING_KEY
rescue Aws::DynamoDB::Errors::ResourceNotFoundException
  false
end

Private Instance Methods

set_schema_before_we_delete_the_table() click to toggle source
# File lib/dynamocli/aws/table.rb, line 39
def set_schema_before_we_delete_the_table
  @schema ||= dynamodb.describe_table(table_name: table_name).to_h[:table].tap do |schema|
    schema.delete(:table_status)
    schema.delete(:creation_date_time)
    schema.delete(:table_size_bytes)
    schema.delete(:item_count)
    schema.delete(:table_arn)
    schema.delete(:table_id)
    schema[:provisioned_throughput]&.delete(:number_of_decreases_today)
    schema[:local_secondary_indexes]&.each do |lsi|
      lsi.delete(:index_status)
      lsi.delete(:index_size_bytes)
      lsi.delete(:item_count)
      lsi.delete(:index_arn)
    end
    schema[:global_secondary_indexes]&.each do |gsi|
      gsi.delete(:index_status)
      gsi.delete(:index_size_bytes)
      gsi.delete(:item_count)
      gsi.delete(:index_arn)
      gsi[:provisioned_throughput].delete(:number_of_decreases_today)
    end
  end
end
status() click to toggle source
# File lib/dynamocli/aws/table.rb, line 35
def status
  dynamodb.describe_table(table_name: table_name).table.table_status
end