Sha256: 06cf256b9c3e2aef1748dedb14d6c232566c91e0682ee6bead5017fd996b25ae

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
class Rack::App::Router::Tree

  require 'rack/app/router/tree/env'

  require 'rack/app/router/tree/branch'
  require 'rack/app/router/tree/leaf'
  require 'rack/app/router/tree/vein'

  attr_reader :root

  def initialize
    @root = self.class::Branch.new
  end

  def add(endpoint)
    @root.set(self.class::Env.new(endpoint))
  end

  def call(env)
    configure_request(env)
    @root.call(env, *env[Rack::App::Constants::ENV::SPLITTED_PATH_INFO])
  end

  protected

  E = Rack::App::Constants::ENV

  def configure_request(env)
    env[E::PATH_SEGMENTS_PARAMS] ||= {}
    env[E::PARAMS] ||= Rack::App::Params.new(env)
    fpi = format_path_info(env).freeze
    env[E::FORMATTED_PATH_INFO] = fpi
    spi = split_path_info(fpi).freeze
    env[E::SPLITTED_PATH_INFO] = spi
    env[E::EXTNAME] = extname(spi)
  end

  def format_path_info(env)
    Rack::App::Utils.normalize_path(env[E::PATH_INFO])
  end

  def split_path_info(formatted_path_info)
    Rack::App::Utils.split_path_info(formatted_path_info)
  end

  def extname(splitted_path_info)
    File.extname(splitted_path_info.last)
  end

end

Version data entries

41 entries across 41 versions & 2 rubygems

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