Module: DataMapped::Searchable

Defined in:
lib/data_mapped/searchable.rb

Defined Under Namespace

Classes: DataAccessor, InstanceAdapter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/data_mapped/searchable.rb', line 27

def self.included(other)
  other.class_eval { alias_method(:new_record?, :new?) }
  other.extend Sunspot::Rails::Searchable::ActsAsMethods
  Sunspot::Adapters::DataAccessor.register(DataAccessor, other)
  Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, other)

  other.class.instance_eval do
    %w[before_save after_save after_destroy].each do |method_name|
      define_method(method_name) do |*args, &block|
        preposition, verb = method_name.split('_').map(&:to_sym)
        method(preposition).call(verb, *args, &block)
      end
    end
  end

  def other.find_in_batches(options = {})
    batch_size, total, offset = options.delete(:batch_size), count, 0
    while offset < total
      yield all(offset: offset, limit: batch_size)
      offset += batch_size
    end
  end

  def other.logger
    ::DataMapper.logger
  end
end

Instance Method Details

#reindexObject



55
56
57
58
# File 'lib/data_mapped/searchable.rb', line 55

def reindex
  Sunspot.index(self)
  Sunspot.commit
end