Sha256: 51370e6a945f98305a22fc86f13933b442fa64cecb056ec25a168c0860772031

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Mongoid
  module Elasticsearch
    module Callbacks
      extend ActiveSupport::Concern

      included do
        ## COMMENTED OUT THIS LINE, SO THAT WE CAN DO THE CREATE MANUALLY.
        #after_save :update_es_index
        after_destroy :update_es_index
          



        ## THIS FUNCTION HAS BEEN UPDATED TO DO THE UPDATE ONLY IF THE OP_SUCCESS IS TRUE OR NIL, IN CASE THE RECORD RESPONDS TO OP_SUCCESS.
        def update_es_index
          
          if self.respond_to? :op_success
          
            if self.op_success.nil?
          
              es_update
            else
          
              es_update if self.op_success == true
            end
          else
          
            es_update
          end
          
        end
      end

      module ClassMethods
        def without_es_update!( &block )
          skip_callback( :save, :after, :update_es_index )
          skip_callback( :destroy, :after, :update_es_index )
          
          result = yield

          set_callback( :save, :after, :update_es_index )
          set_callback( :destroy, :after, :update_es_index )
          
          result
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wj-mongoid-elasticsearch-0.0.9 lib/mongoid/elasticsearch/callbacks.rb
wj-mongoid-elasticsearch-0.0.8 lib/mongoid/elasticsearch/callbacks.rb
wj-mongoid-elasticsearch-0.0.7 lib/mongoid/elasticsearch/callbacks.rb
wj-mongoid-elasticsearch-0.0.6 lib/mongoid/elasticsearch/callbacks.rb