Module: TinyDyno::Tables::ClassMethods

Defined in:
lib/tiny_dyno/tables.rb

Class Method Summary collapse

Instance Method Summary collapse

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.

Examples:

TinyDyno::Tables.option :required do |model, field, value|
  model.validates_presence_of field if value
end

Parameters:

  • option_name (Symbol)

    the option name to match against

  • block (Proc)

    the handler to execute when the option is provided.

Since:

  • 2.1.0



38
39
40
# File 'lib/tiny_dyno/tables.rb', line 38

def option(option_name, &block)
  options[option_name] = block
end

.optionsHash

Return a map of custom option names to their handlers.

Examples:

TinyDyno::Tables.options
# => { :required => #<Proc:0x00000100976b38> }

Returns:

  • (Hash)

    the option map

Since:

  • 2.1.0



51
52
53
# File 'lib/tiny_dyno/tables.rb', line 51

def options
  @options ||= {}
end

Instance Method Details

#create_tabletrue

Send the actual table creation to the DynamoDB API

Examples:

Create the table for the class

Person.create_table

Returns:

  • (true)

    If the operation succeeded



60
61
62
63
# File 'lib/tiny_dyno/tables.rb', line 60

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_tabletrue

Request the table to be deleted

Examples:

Delete the table for the class

Person.delete_table

Returns:

  • (true)

    If the operation succeeded



70
71
72
# File 'lib/tiny_dyno/tables.rb', line 70

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

Examples:

Return the table name for the class

Person.table_name

Returns:

  • (String)

    The name of the table



80
81
82
# File 'lib/tiny_dyno/tables.rb', line 80

def model_table_config_is_valid?
  return (attribute_definitions_meet_spec? and not self.table_name.nil?)
end