Skip to content
Browse files

Adding in test middleware for #2445

  • Loading branch information...
1 parent 43ef8b3 commit 26637a16cc2e5749d090bd6bf523b7ea2a6f4e48 @durran durran committed Oct 21, 2012
Showing with 44 additions and 0 deletions.
  1. +44 −0 lib/rack/mongoid/middleware/streaming/identity_map.rb
View
44 lib/rack/mongoid/middleware/streaming/identity_map.rb
@@ -0,0 +1,44 @@
+# encoding: utf-8
+module Rack
+ module Mongoid
+ module Middleware
+ module Streaming
+
+ # This middleware contains the behaviour needed to properly use the
+ # identity map in Rack based applications.
+ 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
+end

0 comments on commit 26637a1

Please sign in to comment.
Something went wrong with that request. Please try again.