Module: Dynamoid::Indexes::ClassMethods

Defined in:
lib/dynamoid/indexes.rb

Instance Method Summary collapse

Instance Method Details

#create_indexesObject

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

Since:

  • 0.2.0



41
42
43
44
45
46
47
# 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) ⇒ Object

Helper function to find indexes.

Since:

  • 0.2.0



34
35
36
# 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 = {}) ⇒ Object

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



25
26
27
28
29
# 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