Class: AgnosticBackend::Indexable::Config
- Inherits:
-
Object
- Object
- AgnosticBackend::Indexable::Config
- Defined in:
- lib/agnostic_backend/indexable/config.rb
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
- .configure_index(indexable_class, index_class, **options) ⇒ Object
- .configure_secondary_index(indexable_class, index_class, **options) ⇒ Object
- .create_index_for(indexable_class) ⇒ Object
- .create_indices_for(indexable_class, include_primary: true) ⇒ Object
- .indices ⇒ Object
Class Method Details
.configure_index(indexable_class, index_class, **options) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/agnostic_backend/indexable/config.rb', line 32 def self.configure_index(indexable_class, index_class, **) indices[indexable_class.name] = [Entry.new(index_class: index_class, indexable_class: indexable_class, primary: true, **)] end |
.configure_secondary_index(indexable_class, index_class, **options) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/agnostic_backend/indexable/config.rb', line 39 def self.configure_secondary_index(indexable_class, index_class, **) 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, **) end |
.create_index_for(indexable_class) ⇒ Object
49 50 51 52 |
# 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) ⇒ Object
54 55 56 57 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/agnostic_backend/indexable/config.rb', line 28 def self.indices @indices ||= {} end |