Class: Serverspec::Type::AWS::DynamoDB::Table
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::AWS::DynamoDB::Table
- Defined in:
- lib/resources/dynamodb/table.rb
Overview
The Table class exposes the DynamoDB::Table resources
Instance Method Summary collapse
-
#attribute_definitions ⇒ Array(Hash)
An array of AttributeDefinition objects.
-
#global_secondary_indexed? ⇒ Boolean
Returns true if there is a global secondary index.
-
#global_secondary_indexes ⇒ Array(Hash)
The global secondary indexes, if any, on the Table.
-
#hash_key_name ⇒ String
The name of the hash key from the key_schema.
-
#hash_key_type ⇒ Symbol
The type of the hash key from the key_schema.
-
#initialize(tbl_name, instance = nil) ⇒ Table
constructor
AWS SDK for Ruby v2 Aws::DynamoDB::Client wrapper for initializing a Table resource.
-
#key_schema ⇒ Array(Hash)
The primary key structure for the Table.
-
#local_secondary_indexed? ⇒ Boolean
Returns true if there is a local secondary index.
-
#local_secondary_indexes ⇒ Array(Hash)
Represents one or more local secondary indexes on the Table.
-
#range_key_name ⇒ String
The name of the range key from the key_schema.
-
#range_key_type ⇒ Symbol
The type of the range key from the key_schema.
-
#read_capacity ⇒ Integer
The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException.
-
#to_s ⇒ String
Returns the String representation of DynamoDB::Table.
-
#valid? ⇒ Boolean
Returns true if the Table is active.
-
#with_hash_key? ⇒ Boolean
Returns true if the Table has a hash key.
-
#with_range_key? ⇒ Boolean
Returns true if the Table has a range key.
-
#write_capacity ⇒ Integer
The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException.
Constructor Details
#initialize(tbl_name, instance = nil) ⇒ Table
AWS SDK for Ruby v2 Aws::DynamoDB::Client wrapper for initializing a Table resource
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/resources/dynamodb/table.rb', line 14 def initialize(tbl_name, instance = nil) check_init_arg 'tbl_name', 'DynamoDB::Table', tbl_name @tbl_name = tbl_name @aws = instance.nil? ? Aws::DynamoDB::Client.new : instance get_table tbl_name @type_map = { 'S' => :string, 'N' => :number, 'B' => :binary } end |
Instance Method Details
#attribute_definitions ⇒ Array(Hash)
An array of AttributeDefinition objects. Each of these objects describes one attribute in the Table and index key schema
61 62 63 |
# File 'lib/resources/dynamodb/table.rb', line 61 def attribute_definitions @table.attribute_definitions end |
#global_secondary_indexed? ⇒ Boolean
Returns true if there is a global secondary index
54 55 56 |
# File 'lib/resources/dynamodb/table.rb', line 54 def global_secondary_indexed? @table.global_secondary_indexes.is_a?(Array) end |
#global_secondary_indexes ⇒ Array(Hash)
The global secondary indexes, if any, on the Table. Each index is scoped to a given hash key value
95 96 97 |
# File 'lib/resources/dynamodb/table.rb', line 95 def global_secondary_indexes @table.global_secondary_indexes end |
#hash_key_name ⇒ String
The name of the hash key from the key_schema
101 102 103 104 105 |
# File 'lib/resources/dynamodb/table.rb', line 101 def hash_key_name @table.key_schema.each do |key| return key.attribute_name if key.key_type == 'HASH' end end |
#hash_key_type ⇒ Symbol
The type of the hash key from the key_schema. Valid return values: :string, :number, or :binary
110 111 112 113 114 115 116 117 118 |
# File 'lib/resources/dynamodb/table.rb', line 110 def hash_key_type @table.attribute_definitions.each do |attr| if attr.attribute_name == hash_key_name return @type_map[ attr.attribute_type ] end end end |
#key_schema ⇒ Array(Hash)
The primary key structure for the Table
67 68 69 |
# File 'lib/resources/dynamodb/table.rb', line 67 def key_schema @table.key_schema end |
#local_secondary_indexed? ⇒ Boolean
Returns true if there is a local secondary index
49 50 51 |
# File 'lib/resources/dynamodb/table.rb', line 49 def local_secondary_indexed? @table.local_secondary_indexes.is_a?(Array) end |
#local_secondary_indexes ⇒ Array(Hash)
Represents one or more local secondary indexes on the Table. Each index is scoped to a given hash key value
88 89 90 |
# File 'lib/resources/dynamodb/table.rb', line 88 def local_secondary_indexes @table.local_secondary_indexes end |
#range_key_name ⇒ String
The name of the range key from the key_schema
122 123 124 125 126 |
# File 'lib/resources/dynamodb/table.rb', line 122 def range_key_name @table.key_schema.each do |key| return key.attribute_name if key.key_type == 'RANGE' end end |
#range_key_type ⇒ Symbol
The type of the range key from the key_schema. Valid return values: :string, :number, or :binary
131 132 133 134 135 136 137 138 139 |
# File 'lib/resources/dynamodb/table.rb', line 131 def range_key_type @table.attribute_definitions.each do |attr| if attr.attribute_name == range_key_name return @type_map[ attr.attribute_type ] end end end |
#read_capacity ⇒ Integer
The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException
74 75 76 |
# File 'lib/resources/dynamodb/table.rb', line 74 def read_capacity @table.provisioned_throughput.read_capacity_units end |
#to_s ⇒ String
Returns the String representation of DynamoDB::Table
29 30 31 |
# File 'lib/resources/dynamodb/table.rb', line 29 def to_s "DynamoDB Table: #{@tbl_name}" end |
#valid? ⇒ Boolean
Returns true if the Table is active
34 35 36 |
# File 'lib/resources/dynamodb/table.rb', line 34 def valid? @table.table_status == 'ACTIVE' end |
#with_hash_key? ⇒ Boolean
Returns true if the Table has a hash key
39 40 41 |
# File 'lib/resources/dynamodb/table.rb', line 39 def with_hash_key? key_type?('hash') end |
#with_range_key? ⇒ Boolean
Returns true if the Table has a range key
44 45 46 |
# File 'lib/resources/dynamodb/table.rb', line 44 def with_range_key? key_type?('range') end |
#write_capacity ⇒ Integer
The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException
81 82 83 |
# File 'lib/resources/dynamodb/table.rb', line 81 def write_capacity @table.provisioned_throughput.write_capacity_units end |