Sha256: ace70d164529b3340d2edbe39d88181520ff2b1921e1ac86c47b753d2685e36b

Contents?: true

Size: 977 Bytes

Versions: 24

Compression:

Stored size: 977 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.params)
  end

  def wrap(app, params)
    builder = Rack::Builder.new
    builder.use(Rack::App::Middlewares::SetPathParams, params)
    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

24 entries across 24 versions & 1 rubygems

Version Path
rack-app-7.5.1 lib/rack/app/router/tree/vein.rb
rack-app-7.5.0 lib/rack/app/router/tree/vein.rb
rack-app-7.4.0 lib/rack/app/router/tree/vein.rb
rack-app-7.3.2 lib/rack/app/router/tree/vein.rb
rack-app-7.3.1 lib/rack/app/router/tree/vein.rb
rack-app-7.3.0 lib/rack/app/router/tree/vein.rb
rack-app-7.2.2 lib/rack/app/router/tree/vein.rb
rack-app-7.2.1 lib/rack/app/router/tree/vein.rb
rack-app-7.2.0 lib/rack/app/router/tree/vein.rb
rack-app-7.1.0 lib/rack/app/router/tree/vein.rb
rack-app-7.0.0 lib/rack/app/router/tree/vein.rb
rack-app-6.8.0 lib/rack/app/router/tree/vein.rb
rack-app-6.7.1 lib/rack/app/router/tree/vein.rb
rack-app-6.7.0 lib/rack/app/router/tree/vein.rb
rack-app-6.6.0 lib/rack/app/router/tree/vein.rb
rack-app-6.5.0 lib/rack/app/router/tree/vein.rb
rack-app-6.4.1 lib/rack/app/router/tree/vein.rb
rack-app-6.4.0 lib/rack/app/router/tree/vein.rb
rack-app-6.3.3 lib/rack/app/router/tree/vein.rb
rack-app-6.3.2 lib/rack/app/router/tree/vein.rb