21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/elastic/railties/indexable_record.rb', line 21
def index(on: nil, unindex: true, delayed: true)
index_m, unindex_m = delayed ? [:index_later, :unindex_later] : [:index_now, :unindex_now]
if on == :create
after_create { public_send(index_m) }
elsif on == :save
after_save { public_send(index_m) }
else
raise ArgumentError, 'must provide an indexing target when calling index \
(ie: `index on: :save`)'
end
before_destroy { public_send(unindex_m) } if unindex
end
|