Module: Dynamoid::Indexes::ClassMethods
- Defined in:
- lib/dynamoid/indexes.rb
Instance Method Summary collapse
-
#create_indexes ⇒ Object
Helper function to create indexes (if they don’t exist already).
-
#find_index(index) ⇒ Object
Helper function to find indexes.
-
#index(name, options = {}) ⇒ Object
The call to create an index.
Instance Method Details
#create_indexes ⇒ Object
Helper function to create indexes (if they don’t exist already).
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.
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.
25 26 27 28 29 |
# File 'lib/dynamoid/indexes.rb', line 25 def index(name, = {}) index = Dynamoid::Indexes::Index.new(self, name, ) self.indexes[index.name] = index create_indexes end |