Sha256: 72e6a9d2b0655b052303b186f7d6c7bc63bedb77c8407623c79787df6cdd15a5

Contents?: true

Size: 964 Bytes

Versions: 17

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true
class Rack::App::Router::Tree::Vein < ::Hash

  def set(env)
    app = create_app(env)
    request_methods(env).each do |request_method|
      self[request_method.to_s.upcase] = app
    end
  end

  def call(env)
    app = app_by(env)
    app && app.call(env)
  end

  protected

  def app_by(env)
    self[env[Rack::App::Constants::ENV::REQUEST_METHOD]]
  end

  def create_app(env)
    app = env.endpoint.to_app
    env.params.empty? ? app : wrap(app, env)
  end

  def wrap(app, env)
    builder = Rack::Builder.new
    builder.use(Rack::App::Middlewares::SetPathParams, env)
    builder.run(app)
    builder.to_app
  end

  def request_methods(env)
    request_method = env.endpoint.request_method
    case request_method || raise('missing config: request_methods')
    when Rack::App::Constants::HTTP::METHOD::ANY
      Rack::App::Constants::HTTP::METHODS
    else
      [request_method].flatten.map(&:to_sym)
    end
  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/router/tree/vein.rb
rack-app-11.0.1 lib/rack/app/router/tree/vein.rb
rack-app-11.0.0 lib/rack/app/router/tree/vein.rb
rack-app-10.0.0 lib/rack/app/router/tree/vein.rb
rack-app-9.0.0 lib/rack/app/router/tree/vein.rb
rack-app-8.1.0 lib/rack/app/router/tree/vein.rb
rack-app-8.0.1 lib/rack/app/router/tree/vein.rb
rack-app-8.0.0 lib/rack/app/router/tree/vein.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/router/tree/vein.rb
rack-app-7.7.0 lib/rack/app/router/tree/vein.rb
rack-app-7.6.5 lib/rack/app/router/tree/vein.rb
rack-app-7.6.4 lib/rack/app/router/tree/vein.rb
rack-app-7.6.3 lib/rack/app/router/tree/vein.rb
rack-app-7.6.2 lib/rack/app/router/tree/vein.rb
rack-app-7.6.1 lib/rack/app/router/tree/vein.rb
rack-app-7.6.0 lib/rack/app/router/tree/vein.rb
rack-app-7.5.2 lib/rack/app/router/tree/vein.rb