Sha256: f0094028c1746de886a430370d53b20bfebe49c11e7f61de5f4fc961c22aee0b

Contents?: true

Size: 686 Bytes

Versions: 3

Compression:

Stored size: 686 Bytes

Contents

require "scorpion/rack/env"

module Scorpion
  module Rack
    class Middleware

      ENV_KEY = "scorpion.rack.instance".freeze

      def initialize( app, nest = nil )
        @app  = app
        @nest = nest || Scorpion.instance.build_nest
      end

      def call( env )
        env[ENV_KEY] = prepare_scorpion( nest.conceive, env )
        @app.call(env).tap do
          free_scorpion( env )
        end
      end

      private

        attr_reader :nest

        def prepare_scorpion( scorpion, env )
          scorpion.hunt_for Rack::Env, return: env
          scorpion
        end

        def free_scorpion( env )
          env[ENV_KEY].destroy
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.2 lib/scorpion/rack/middleware.rb
scorpion-ioc-1.0.1 lib/scorpion/rack/middleware.rb
scorpion-ioc-1.0.0 lib/scorpion/rack/middleware.rb