Class: Picky::Indexes
- Extended by:
- Helpers::Indexing
- Includes:
- Helpers::Indexing
- Defined in:
- lib/picky/indexes.rb,
lib/picky/indexes_indexed.rb,
lib/picky/indexes_indexing.rb,
lib/picky/indexes_convenience.rb
Overview
Indexes indexing.
Instance Attribute Summary collapse
-
#index_mapping ⇒ Object
readonly
Returns the value of attribute index_mapping.
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
Class Method Summary collapse
- .identifier ⇒ Object
-
.index(scheduler = Scheduler.new) ⇒ Object
Overrides index from the helper.
-
.instance ⇒ Object
Return the Indexes instance.
- .optimize_memory(array_references = Hash.new) ⇒ Object
- .register(index) ⇒ Object
Instance Method Summary collapse
-
#[](identifier) ⇒ Object
Extracts an index, given its identifier.
-
#clear_indexes ⇒ Object
Clears the indexes and the mapping.
-
#initialize(*indexes) ⇒ Indexes
constructor
A new instance of Indexes.
-
#optimize_memory(array_references = Hash.new) ⇒ Object
Tries to optimize the memory usage of the indexes.
-
#raise_not_found(index_name) ⇒ Object
Raises a not found for the index.
-
#register(index) ⇒ Object
Registers an index with the indexes.
- #to_s ⇒ Object
- #tokenizer ⇒ Object
Methods included from Helpers::Indexing
Methods included from Helpers::Measuring
Constructor Details
#initialize(*indexes) ⇒ Indexes
Returns a new instance of Indexes.
26 27 28 29 |
# File 'lib/picky/indexes.rb', line 26 def initialize *indexes clear_indexes indexes.each { |index| register index } end |
Instance Attribute Details
#index_mapping ⇒ Object (readonly)
Returns the value of attribute index_mapping.
11 12 13 |
# File 'lib/picky/indexes.rb', line 11 def index_mapping @index_mapping end |
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
11 12 13 |
# File 'lib/picky/indexes.rb', line 11 def indexes @indexes end |
Class Method Details
.identifier ⇒ Object
36 37 38 |
# File 'lib/picky/indexes.rb', line 36 def self.identifier name end |
.index(scheduler = Scheduler.new) ⇒ Object
Overrides index from the helper.
16 17 18 19 20 |
# File 'lib/picky/indexes_indexing.rb', line 16 def self.index scheduler = Scheduler.new timed_indexing scheduler do instance.index scheduler end end |
.instance ⇒ Object
Return the Indexes instance.
33 34 35 |
# File 'lib/picky/indexes.rb', line 33 def self.instance @instance ||= new end |
.optimize_memory(array_references = Hash.new) ⇒ Object
55 56 57 |
# File 'lib/picky/indexes.rb', line 55 def self.optimize_memory array_references = Hash.new self.instance.optimize_memory array_references end |
.register(index) ⇒ Object
68 69 70 |
# File 'lib/picky/indexes.rb', line 68 def self.register index self.instance.register index end |
Instance Method Details
#[](identifier) ⇒ Object
Extracts an index, given its identifier.
74 75 76 77 |
# File 'lib/picky/indexes.rb', line 74 def [] identifier index_name = identifier.intern index_mapping[index_name] || raise_not_found(index_name) end |
#clear_indexes ⇒ Object
Clears the indexes and the mapping.
42 43 44 45 |
# File 'lib/picky/indexes.rb', line 42 def clear_indexes @indexes = [] @index_mapping = Hash.new end |
#optimize_memory(array_references = Hash.new) ⇒ Object
Tries to optimize the memory usage of the indexes.
49 50 51 52 53 54 |
# File 'lib/picky/indexes.rb', line 49 def optimize_memory array_references = Hash.new dedup = Picky::Optimizers::Memory::ArrayDeduplicator.new @indexes.each do |index| index.optimize_memory array_references end end |
#raise_not_found(index_name) ⇒ Object
Raises a not found for the index.
81 82 83 |
# File 'lib/picky/indexes.rb', line 81 def raise_not_found index_name raise %Q{Index "#{index_name}" not found. Possible indexes: "#{indexes.map(&:name).join('", "')}".} end |
#register(index) ⇒ Object
Registers an index with the indexes.
61 62 63 64 65 66 67 |
# File 'lib/picky/indexes.rb', line 61 def register index # TODO Do not store duplicate indexes. # # self.indexes.delete_if { |existing| existing.name == index.name } self.indexes << index self.index_mapping[index.name] = index end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/picky/indexes.rb', line 87 def to_s indexes.indented_to_s end |