class ChewyResque::Index
Attributes
index_name[R]
Public Class Methods
new(backref: :self, index: nil, queue: nil, only_if: nil)
click to toggle source
# File lib/chewy_resque/index.rb, line 9 def initialize(backref: :self, index: nil, queue: nil, only_if: nil) @only_if = only_if @index_name = index @backref_method = backref @queue = queue end
Public Instance Methods
backref(object)
click to toggle source
# File lib/chewy_resque/index.rb, line 26 def backref(object) return @backref_method.call(object) if @backref_method.respond_to?(:call) return object if @backref_method.to_s == 'self' object.send(@backref_method) end
backref_ids(object)
click to toggle source
# File lib/chewy_resque/index.rb, line 32 def backref_ids(object) Array.wrap(backref(object)).map { |object| object.respond_to?(:id) ? object.id : object.to_i } end
enqueue(object)
click to toggle source
# File lib/chewy_resque/index.rb, line 16 def enqueue(object) return if @only_if.respond_to?(:call) && @only_if.call(object) if (ids = backref_ids(object).compact).present? Resque.enqueue_to(@queue || Resque.queue_from_class(ChewyResque::Worker), ChewyResque::Worker, @index_name, ids) end end