Sha256: 3f035237318dfa2950dd025d1c79a9d4fe348e7c60e2db132ac53482ce1691e1

Contents?: true

Size: 1009 Bytes

Versions: 3

Compression:

Stored size: 1009 Bytes

Contents

module Neo4j
  module Rails
    # close lucene connections
    # reset the Neo4j.threadlocal_ref_node (Multitenancy)
    # clear the identity map
    class Middleware
      class Body #:nodoc:
        def initialize(target, original)
          @target = target
          @original = original
        end

        def each(&block)
          @target.each(&block)
        end

        def close
          @target.close if @target.respond_to?(:close)
        ensure
          IdentityMap.enabled = @original
          IdentityMap.clear
        end
      end

      def initialize(app)
        @app = app
      end

      def call(env)
        enabled = IdentityMap.enabled
        IdentityMap.enabled = Neo4j::Config[:identity_map]
        status, headers, body = @app.call(env)
        [status, headers, Body.new(body, enabled)]
      ensure
        IdentityMap.clear
        Neo4j::Rails::Model.close_lucene_connections
        Neo4j.threadlocal_ref_node = Neo4j.default_ref_node
      end
    end

  end


end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neo4j-2.3.0-java lib/neo4j/rails/rack_middleware.rb
neo4j-2.2.4-java lib/neo4j/rails/rack_middleware.rb
neo4j-2.2.3-java lib/neo4j/rails/rack_middleware.rb