35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/data_mapped/searchable.rb', line 35
def self.included(other)
other.class_eval do
alias_method(:new_record?, :new?)
after :save, :reindex
after :destroy, :reindex
end
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
|