Sha256: 77c2d88daab4ded053c8da2a6917af8adbda7dfea5f1409fc4cd91bd36b3ed47

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

module TireAsyncIndex
  module Workers

    # Worker for updating ElasticSearch index
    class UpdateIndex

      # Update or delete ElasticSearch index based on the action_type parameter.
      #
      # Parameters:
      #   action_type - Determine index direction. (allowed value - Update or Delete)
      #   class_name - Model class name
      #   id - Document id
      #
      def perform(action_type, class_name, id)
        klass = Kernel.const_get(class_name)

        case action_type.to_sym
          when :update
            object = klass.find(id)

            if object.present? && object.respond_to?(:tire)
              object.tire.update_index
            end
          when :delete

            klass.new.tap do |inst|
              inst.tire.index.remove(inst.tire.document_type, { _id: id })
            end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tire_async_index-0.2.0 lib/tire_async_index/workers/update_index.rb