class ChewyKiqqer::Index

Public Class Methods

new(backref: :self, index: nil, queue: ChewyKiqqer.default_queue) click to toggle source
# File lib/chewy_kiqqer/index.rb, line 5
def initialize(backref: :self, index: nil, queue: ChewyKiqqer.default_queue)
  @index_name = index
  @backref_method = backref
  @queue = queue
end

Public Instance Methods

backref(object) click to toggle source
# File lib/chewy_kiqqer/index.rb, line 15
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_kiqqer/index.rb, line 21
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_kiqqer/index.rb, line 11
def enqueue(object)
  Sidekiq::Client.push('queue' => @queue, 'class' => ChewyKiqqer::Worker, 'args' => [@index_name, backref_ids(object)])
end