Sha256: a3c7156c5fd5652aa120c4ede3707fb6a826036b9e1cffc21dd7de34235256ed

Contents?: true

Size: 685 Bytes

Versions: 15

Compression:

Stored size: 685 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

15 entries across 15 versions & 1 rubygems

Version Path
scorpion-ioc-0.6.2 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.6.1 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.6.0 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.23 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.22 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.21 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.20 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.19 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.18 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.17 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.16 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.15 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.14 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.13 lib/scorpion/rack/middleware.rb
scorpion-ioc-0.5.12 lib/scorpion/rack/middleware.rb