Sha256: 4ed24488c970512ce59168e9cf72e4f9a16fb96657fb4104d7bbfdf469046ad8

Contents?: true

Size: 759 Bytes

Versions: 10

Compression:

Stored size: 759 Bytes

Contents

module Toy
  module Middleware
    class IdentityMap
      class Body
        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
          Toy::IdentityMap.enabled = @original
          Toy::IdentityMap.clear
        end
      end

      def initialize(app)
        @app = app
      end

      def call(env)
        Toy::IdentityMap.clear
        enabled = Toy::IdentityMap.enabled
        Toy::IdentityMap.enabled = true
        status, headers, body = @app.call(env)
        [status, headers, Body.new(body, enabled)]
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
toystore-0.13.1 lib/toy/middleware/identity_map.rb
toystore-0.13.0 lib/toy/middleware/identity_map.rb
toystore-0.12.0 lib/toy/middleware/identity_map.rb
toystore-0.11.0 lib/toy/middleware/identity_map.rb
toystore-0.10.4 lib/toy/middleware/identity_map.rb
toystore-0.10.3 lib/toy/middleware/identity_map.rb
toystore-0.10.2 lib/toy/middleware/identity_map.rb
toystore-0.10.1 lib/toy/middleware/identity_map.rb
toystore-0.10.0 lib/toy/middleware/identity_map.rb
toystore-0.9.0 lib/toy/middleware/identity_map.rb