Sha256: 8e6c2837229e29d63b61e33eb0ae8cf3710e5d2c82ae31862a342620f37d2713

Contents?: true

Size: 1.07 KB

Versions: 33

Compression:

Stored size: 1.07 KB

Contents

require "rack/builder"
require "rack/request"
require "rack/response"
class Rack::App::Middlewares::Configuration

  def initialize(app, config)
    @app = app || raise
    @serializer = config.serializer || raise
    @handler_class = config.app_class || raise
    @payload_parser = config.payload_builder.to_parser || raise
  end

  def call(env)
    env[::Rack::App::Constants::ENV::HANDLER]= handler(env)
    env[::Rack::App::Constants::ENV::SERIALIZER]= @serializer
    env[::Rack::App::Constants::ENV::PAYLOAD_PARSER]= @payload_parser
    env[::Rack::App::Constants::ENV::PAYLOAD_GETTER]= lambda do
      env[::Rack::App::Constants::ENV::PARSED_PAYLOAD] ||= env[::Rack::App::Constants::ENV::PAYLOAD_PARSER].parse_env(env)
    end
    @app.call(env)
  end

  protected

  def handler(env)
    new_handler = @handler_class.new
    new_handler.request = ::Rack::Request.new(env)
    new_handler.response = ::Rack::Response.new
    new_handler
  end

  def extname(env)
    path_info = env[::Rack::App::Constants::ENV::PATH_INFO]
    File.extname(path_info.split("/").last.to_s)
  end

end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
rack-app-8.1.0 lib/rack/app/middlewares/configuration.rb
rack-app-8.0.1 lib/rack/app/middlewares/configuration.rb
rack-app-8.0.0 lib/rack/app/middlewares/configuration.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/middlewares/configuration.rb
rack-app-7.7.0 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.5 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.4 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.3 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.2 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.1 lib/rack/app/middlewares/configuration.rb
rack-app-7.6.0 lib/rack/app/middlewares/configuration.rb
rack-app-7.5.2 lib/rack/app/middlewares/configuration.rb
rack-app-7.5.1 lib/rack/app/middlewares/configuration.rb
rack-app-7.5.0 lib/rack/app/middlewares/configuration.rb
rack-app-7.4.0 lib/rack/app/middlewares/configuration.rb
rack-app-7.3.2 lib/rack/app/middlewares/configuration.rb
rack-app-7.3.1 lib/rack/app/middlewares/configuration.rb
rack-app-7.3.0 lib/rack/app/middlewares/configuration.rb
rack-app-7.2.2 lib/rack/app/middlewares/configuration.rb
rack-app-7.2.1 lib/rack/app/middlewares/configuration.rb