Class: Heliosphere::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/heliosphere/indexer.rb

Constant Summary collapse

SEARCH_WITHOUT_LIFECYCLE =
{ :auto_index => false, :auto_remove => false }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blockObject

Returns the value of attribute block.



11
12
13
# File 'lib/heliosphere/indexer.rb', line 11

def block
  @block
end

Instance Method Details

#applyObject



22
23
24
25
26
27
28
29
# File 'lib/heliosphere/indexer.rb', line 22

def apply
  options = SEARCH_WITHOUT_LIFECYCLE
  model_definitions.each do |model, block|
    model.instance_eval do
      searchable(options, &block)
    end
  end
end

#define(&block) ⇒ Object



13
14
15
16
# File 'lib/heliosphere/indexer.rb', line 13

def define(&block)
  instance_eval(&block)
  apply
end

#index(model, &block) ⇒ Object



31
32
33
# File 'lib/heliosphere/indexer.rb', line 31

def index(model, &block)
  model_definitions[model] = block
end

#model_definitionsObject



39
40
41
# File 'lib/heliosphere/indexer.rb', line 39

def model_definitions
  @model_definitions ||= {}
end

#model_namesObject



18
19
20
# File 'lib/heliosphere/indexer.rb', line 18

def model_names
  models.map { |model| model.name.underscore.to_sym }
end

#modelsObject



35
36
37
# File 'lib/heliosphere/indexer.rb', line 35

def models
  model_definitions.keys
end