Module: Dynamoid::Indexes

Extended by:
ActiveSupport::Concern
Included in:
Components
Defined in:
lib/dynamoid/indexes.rb

Overview

Builds all indexes present on the model.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#key_for_index(index) ⇒ Object



46
47
48
# File 'lib/dynamoid/indexes.rb', line 46

def key_for_index(index)
  self.class.key_for_index(index, index.collect{|i| self.send(i)})
end

#save_indexesObject



50
51
52
53
54
55
56
# File 'lib/dynamoid/indexes.rb', line 50

def save_indexes
  self.class.indexes.each do |index|
    existing = Dynamoid::Adapter.get_item(self.class.index_table_name(index), self.key_for_index(index))
    ids = existing ? existing[:ids] : Set.new
    Dynamoid::Adapter.put_item(self.class.index_table_name(index), {self.class.index_key_name(index).to_sym => self.key_for_index(index), :ids => ids.merge([self.id])})
  end
end