Sha256: 44ec88006702de01ce98bc61084cb269a183d8dea0135eeb5e1276f0c82ebfcf

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 Bytes

Contents

module Flipper
  module Middleware
    class LocalCache
      class Body
        def initialize(target, flipper, original)
          @target   = target
          @flipper  = flipper
          @original = original
        end

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

        def close
          @target.close if @target.respond_to?(:close)
        ensure
          @flipper.adapter.use_local_cache = @original
        end
      end

      def initialize(app, flipper)
        @app = app
        @flipper = flipper
      end

      def call(env)
        original = @flipper.adapter.using_local_cache?
        @flipper.adapter.use_local_cache = true

        status, headers, body = @app.call(env)
        [status, headers, Body.new(body, @flipper, original)]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flipper-0.4.0 lib/flipper/middleware/local_cache.rb
flipper-0.3.0 lib/flipper/middleware/local_cache.rb
flipper-0.2.1 lib/flipper/middleware/local_cache.rb
flipper-0.2.0 lib/flipper/middleware/local_cache.rb