lib/elastics/model_indexer.rb in elastics-models-1.0.10 vs lib/elastics/model_indexer.rb in elastics-models-1.1.0

- old
+ new

@@ -5,10 +5,22 @@ 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 def elastics @elastics ||= InstanceProxy::ModelIndexer.new(self) @@ -21,7 +33,6 @@ def elastics_indexable? true end end - end