Sha256: 11dc8e07c21f858f264d7d1c714b2130262e1afedbe61d66ecc162bf590449a5

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8
module Rack
  module Mongoid
    module Middleware

      # This middleware contains the behaviour needed to properly use the
      # identity map in Rack based applications. This middleware will properly
      # handle Rails or Rack streaming responses.
      class IdentityMap

        # Initialize the new middleware.
        #
        # @example Init the middleware.
        #   IdentityMap.new(app)
        #
        # @param [ Object ] app The application.
        #
        # @since 2.1.0
        def initialize(app)
          @app = app
        end

        # Make the request with the provided environment.
        #
        # @example Make the request.
        #   identity_map.call(env)
        #
        # @param [ Object ] env The environment.
        #
        # @return [ Array ] The status, headers, and response.
        #
        # @since 2.1.0
        def call(env)
          response = @app.call(env)
          response[2] = ::Rack::BodyProxy.new(response[2]) do
            ::Mongoid::IdentityMap.clear
          end
          response
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-3.0.10 lib/rack/mongoid/middleware/identity_map.rb