module Dynamoid::Indexes::ClassMethods

Public Instance Methods

create_indexes() click to toggle source

Helper function to create indexes (if they don't exist already).

@since 0.2.0

# File lib/dynamoid/indexes.rb, line 41
def create_indexes
  self.indexes.each do |name, index|
    opts = {:table_name => index.table_name, :id => :id}
    opts[:range_key] = { :range => :number } if index.range_key?
    self.create_table(opts)
  end
end
find_index(index) click to toggle source

Helper function to find indexes.

@since 0.2.0

# File lib/dynamoid/indexes.rb, line 34
def find_index(index)
  self.indexes[Array(index).collect(&:to_s).sort.collect(&:to_sym)]
end
index(name, options = {}) click to toggle source

The call to create an index. Generates a new index with the specified options – for more information, see Dynamoid::Indexes::Index. This function also attempts to immediately create the indexing table if it does not exist already.

@since 0.2.0

# File lib/dynamoid/indexes.rb, line 25
def index(name, options = {})
  index = Dynamoid::Indexes::Index.new(self, name, options)
  self.indexes[index.name] = index
  create_indexes        
end