Class: Dynamodb::Local
- Inherits:
-
Object
- Object
- Dynamodb::Local
- Extended by:
- DynamoDBSchema
- Defined in:
- lib/dynamodb/local.rb
Class Attribute Summary collapse
-
.dynamodb ⇒ Object
readonly
Returns the value of attribute dynamodb.
Class Method Summary collapse
- .build_table_attrs(klass) ⇒ Object
- .create_table(table_name, klass, &block) ⇒ Object
- .provisioned_throughput ⇒ Object
- .reset ⇒ Object
- .splat_error(title, message) ⇒ Object
- .teardown ⇒ Object
Class Attribute Details
.dynamodb ⇒ Object (readonly)
Returns the value of attribute dynamodb.
11 12 13 |
# File 'lib/dynamodb/local.rb', line 11 def dynamodb @dynamodb end |
Class Method Details
.build_table_attrs(klass) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dynamodb/local.rb', line 38 def build_table_attrs(klass) params = { attribute_definitions: klass.attribute_definitions, key_schema: klass.key_schema, provisioned_throughput: provisioned_throughput } params.merge!( local_secondary_indexes: klass.local_indexes ) unless klass.local_indexes.empty? unless klass.global_indexes.empty? global_indexes_hash = klass.global_indexes.map do |x| x.merge({ provisioned_throughput: provisioned_throughput }) end params.merge!( global_secondary_indexes: global_indexes_hash ) end params end |
.create_table(table_name, klass, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/dynamodb/local.rb', line 30 def create_table(table_name, klass, &block) params = build_table_attrs(klass) params.merge!(yield) if block_given? # merge overrides @dynamodb.create_table(table_name, params) rescue Aws::DynamoDB::Errors => e splat_error("Unable to create DynamoDB tables:", e.) end |
.provisioned_throughput ⇒ Object
62 63 64 65 66 67 |
# File 'lib/dynamodb/local.rb', line 62 def provisioned_throughput { read_capacity_units: 10, write_capacity_units: 10 } end |
.reset ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/dynamodb/local.rb', line 13 def reset @dynamodb ||= Dynamodb teardown build_tables # DynamoDBSchema#build_tables rescue => e splat_error("Unable to reset DynamoDB:", e.) end |
.splat_error(title, message) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dynamodb/local.rb', line 69 def splat_error(title, ) puts <<-HEREDOC ############################## #{title} #{} ############################## HEREDOC end |
.teardown ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dynamodb/local.rb', line 22 def teardown @dynamodb.list_tables.each do |table| @dynamodb.delete_table(table) end rescue => e splat_error("Unable to teardown DynamoDB tables:", e.) end |