Class: Heliosphere::Indexer
- Inherits:
-
Object
- Object
- Heliosphere::Indexer
- Defined in:
- lib/heliosphere/indexer.rb
Constant Summary collapse
- SEARCH_WITHOUT_LIFECYCLE =
{ :auto_index => false, :auto_remove => false }
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
Instance Method Summary collapse
- #apply ⇒ Object
- #define(&block) ⇒ Object
- #extend_active_record ⇒ Object
- #index(model, &block) ⇒ Object
- #model_definitions ⇒ Object
- #model_names ⇒ Object
- #models ⇒ Object
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
11 12 13 |
# File 'lib/heliosphere/indexer.rb', line 11 def block @block end |
Instance Method Details
#apply ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/heliosphere/indexer.rb', line 23 def apply = SEARCH_WITHOUT_LIFECYCLE model_definitions.each do |model, block| model.instance_eval do searchable(, &block) end end end |
#define(&block) ⇒ Object
13 14 15 16 17 |
# File 'lib/heliosphere/indexer.rb', line 13 def define(&block) instance_eval(&block) extend_active_record apply end |
#extend_active_record ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/heliosphere/indexer.rb', line 32 def extend_active_record ActiveRecord::Base.class_eval %Q{ def index_on_save? @index_on_save = true unless instance_variable_defined?(:@index_on_save) @index_on_save end def save_without_index @index_on_save = false save @index_on_save = true end def save_without_index! @index_on_save = false save! @index_on_save = true end } end |
#index(model, &block) ⇒ Object
53 54 55 |
# File 'lib/heliosphere/indexer.rb', line 53 def index(model, &block) model_definitions[model] = block end |
#model_definitions ⇒ Object
61 62 63 |
# File 'lib/heliosphere/indexer.rb', line 61 def model_definitions @model_definitions ||= {} end |
#model_names ⇒ Object
19 20 21 |
# File 'lib/heliosphere/indexer.rb', line 19 def model_names models.map { |model| model.name.underscore.to_sym } end |
#models ⇒ Object
57 58 59 |
# File 'lib/heliosphere/indexer.rb', line 57 def models model_definitions.keys end |