Module: TinyDyno::Tables::ClassMethods
- Defined in:
- lib/tiny_dyno/tables.rb
Class Method Summary collapse
-
.option(option_name, &block) ⇒ Object
Stores the provided block to be run when the option name specified is defined on a field.
-
.options ⇒ Hash
Return a map of custom option names to their handlers.
Instance Method Summary collapse
-
#create_table ⇒ true
Soft Create Request, which will accept that a table may already exist.
-
#create_table! ⇒ true
Send the actual table creation to the DynamoDB API and expect no table to be present.
-
#delete_table ⇒ true
Request the table to be deleted.
-
#model_table_config_is_valid? ⇒ String
Return the actual table name that represents the model in the DynamoDB store.
- #table_name ⇒ Object
Class Method Details
.option(option_name, &block) ⇒ Object
Stores the provided block to be run when the option name specified is defined on a field.
No assumptions are made about what sort of work the handler might perform, so it will always be called if the option_name key is provided in the field definition – even if it is false or nil.
41 42 43 |
# File 'lib/tiny_dyno/tables.rb', line 41 def option(option_name, &block) [option_name] = block end |
.options ⇒ Hash
Return a map of custom option names to their handlers.
54 55 56 |
# File 'lib/tiny_dyno/tables.rb', line 54 def ||= {} end |
Instance Method Details
#create_table ⇒ true
Soft Create Request, which will accept that a table may already exist
74 75 76 77 78 79 80 |
# File 'lib/tiny_dyno/tables.rb', line 74 def create_table if TinyDyno::Adapter.table_exists?(table_name: self.table_name) return true end raise InvalidTableDefinition.new "#{ self.name } has invalid table configuration" unless model_table_config_is_valid? TinyDyno::Adapter.create_table(create_table_request) end |
#create_table! ⇒ true
Send the actual table creation to the DynamoDB API and expect no table to be present
64 65 66 67 |
# File 'lib/tiny_dyno/tables.rb', line 64 def create_table! raise InvalidTableDefinition.new "#{ self.name } has invalid table configuration" unless model_table_config_is_valid? TinyDyno::Adapter.create_table(create_table_request) end |
#delete_table ⇒ true
Request the table to be deleted
85 86 87 |
# File 'lib/tiny_dyno/tables.rb', line 85 def delete_table TinyDyno::Adapter.delete_table(table_name: self.table_name) end |
#model_table_config_is_valid? ⇒ String
Return the actual table name that represents the model in the DynamoDB store
95 96 97 |
# File 'lib/tiny_dyno/tables.rb', line 95 def model_table_config_is_valid? return (attribute_definitions_meet_spec? and not self.table_name.nil?) end |
#table_name ⇒ Object
18 19 20 |
# File 'lib/tiny_dyno/tables.rb', line 18 def table_name self.name.to_s.downcase end |