class Lifesaver::Indexing::Indexer

Attributes

class_name[R]
model_id[R]
operation[R]

Public Class Methods

new(args) click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 4
def initialize(args)
  @class_name = args.fetch(:class_name)
  @model_id = args.fetch(:model_id)
  @operation = args.fetch(:operation).to_sym
end

Public Instance Methods

perform() click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 10
def perform
  case operation
  when :update
    store
  when :destroy
    remove
  end
end

Private Instance Methods

index() click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 23
def index
  @index ||= Tire.index(klass.index_name)
end
klass() click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 27
def klass
  @klass ||= class_name.to_s.classify.constantize
end
remove() click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 35
def remove
  index.remove(type: klass.document_type, id: model_id)
end
store() click to toggle source
# File lib/lifesaver/indexing/indexer.rb, line 31
def store
  index.store(klass.find(model_id)) if klass.exists?(model_id)
end