Module: Elastics::ModelIndexer

Defined in:
lib/elastics/model_indexer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/elastics/model_indexer.rb', line 4

def self.included(base)
  base.class_eval do
    @elastics ||= ClassProxy::Base.new(base)
    @elastics.extend(ClassProxy::ModelSyncer)
    @elastics.extend(ClassProxy::ModelIndexer).init
    def self.elastics; @elastics end
    case
    when respond_to?(:find_in_batches)
      def self.elastics_in_batches(options={}, &block)
        find_in_batches(options, &block)
      end
    when defined?(Mongoid::Document) && include?(Mongoid::Document)
      def self.elastics_in_batches(options={}, &block)
        0.step(count, options[:batch_size]) do |offset|
          block.call limit(options[:batch_size]).skip(offset).to_a
        end
      end
    end
  end
end

Instance Method Details

#elasticsObject



25
26
27
# File 'lib/elastics/model_indexer.rb', line 25

def elastics
  @elastics ||= InstanceProxy::ModelIndexer.new(self)
end

#elastics_actionObject



37
38
39
# File 'lib/elastics/model_indexer.rb', line 37

def elastics_action
  'index'
end

#elastics_indexable?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/elastics/model_indexer.rb', line 33

def elastics_indexable?
  true
end

#elastics_sourceObject



29
30
31
# File 'lib/elastics/model_indexer.rb', line 29

def elastics_source
  attributes.reject {|k| k.to_s =~ /^_*id$/}
end