Module: SearchAndResque::Callbacks::ClassMethods
- Defined in:
- lib/search_and_resque/callbacks.rb
Instance Method Summary collapse
- #enqueue_elastic_search_delete(ids) ⇒ Object
- #enqueue_elastic_search_update(ids) ⇒ Object
-
#will_delete_all(ids) ⇒ Object
e.g.
-
#will_update_all(ids) ⇒ Object
e.g.
Instance Method Details
#enqueue_elastic_search_delete(ids) ⇒ Object
11 12 13 14 |
# File 'lib/search_and_resque/callbacks.rb', line 11 def enqueue_elastic_search_delete(ids) ids = Array(ids).map{ |x| x.is_a?(ActiveRecord::Base) ? x.id : x } SearchAndResque.queue.enqueue_delete(elastic_search_type, ids) end |
#enqueue_elastic_search_update(ids) ⇒ Object
6 7 8 9 |
# File 'lib/search_and_resque/callbacks.rb', line 6 def enqueue_elastic_search_update(ids) ids = Array(ids).map{ |x| x.is_a?(ActiveRecord::Base) ? x.id : x } SearchAndResque.queue.enqueue_update(elastic_search_type, ids) end |
#will_delete_all(ids) ⇒ Object
e.g.
Model.will_delete_all(@records) do
...
@records.delete_all
...
end
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/search_and_resque/callbacks.rb', line 40 def will_delete_all(ids) begin skip_callback(:destroy, :after, :enqueue_elastic_search_delete) transaction do yield if block_given? enqueue_elastic_search_delete(ids) unless ids.empty? end ensure set_callback(:destroy, :after, :enqueue_elastic_search_delete) end end |
#will_update_all(ids) ⇒ Object
e.g.
Model.will_update_all(@records) do
...
@records.update_all(...)
...
end
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/search_and_resque/callbacks.rb', line 22 def will_update_all(ids) begin skip_callback(:save, :after, :enqueue_elastic_search_update) transaction do yield if block_given? enqueue_elastic_search_update(ids) unless ids.empty? end ensure set_callback(:save, :after, :enqueue_elastic_search_update) end end |