class AgnosticBackend::Indexable::Config

Public Class Methods

configure_index(indexable_class, index_class, **options) click to toggle source
# File lib/agnostic_backend/indexable/config.rb, line 32
def self.configure_index(indexable_class, index_class, **options)
  indices[indexable_class.name] = [Entry.new(index_class: index_class,
                                             indexable_class: indexable_class,
                                             primary: true,
                                             **options)]
end
configure_secondary_index(indexable_class, index_class, **options) click to toggle source
# File lib/agnostic_backend/indexable/config.rb, line 39
def self.configure_secondary_index(indexable_class, index_class, **options)
  unless indices.has_key? indexable_class.name
    raise "No primary index exists for class #{indexable_class.name}"
  end
  indices[indexable_class.name] << Entry.new(index_class: index_class,
                                             indexable_class: indexable_class,
                                             primary: false,
                                             **options)
end
create_index_for(indexable_class) click to toggle source
# File lib/agnostic_backend/indexable/config.rb, line 49
def self.create_index_for(indexable_class)
  entry = indices[indexable_class.name].find(&:primary?)
  entry.try(:create_index)
end
create_indices_for(indexable_class, include_primary: true) click to toggle source
# File lib/agnostic_backend/indexable/config.rb, line 54
def self.create_indices_for(indexable_class, include_primary: true)
  all = indices[indexable_class.name].map {|entry| entry.try(:create_index)}.compact
  include_primary ? all : all.reject(&:primary?)
end
indices() click to toggle source
# File lib/agnostic_backend/indexable/config.rb, line 28
def self.indices
  @indices ||= {}
end