Sha256: b027b6a75216d602a6774d243e293386cb0d370f65257fd48f6c0bbc72390b1a

Contents?: true

Size: 1.2 KB

Versions: 44

Compression:

Stored size: 1.2 KB

Contents

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

  attr_reader :request_path_parts, :endpoint, :params

  def current
    @request_path_parts[@index]
  end

  def branch?
    !clean_request_path_parts[@index..-2].empty?
  end

  def type
    case @request_path_parts.last
    when Rack::App::Constants::PATH::APPLICATION
      :APPLICATION
    when Rack::App::Constants::PATH::MOUNT_POINT
      :MOUNT_POINT
    else
      :ENDPOINT
    end
  end

  def save_key
    if current =~ /^:\w+$/i
      @params[@index]= current.sub(/^:/, '')
      :ANY
    else
      current
    end
  end

  def next
    env = self.dup
    env.inc_index!
    env
  end

  protected

  def initialize(endpoint)
    @index = 0
    @params = {}
    @endpoint = endpoint
    @request_path_parts = request_path_parts_by(endpoint).freeze
  end

  def request_path_parts_by(endpoint)
    u = Rack::App::Utils
    u.split_path_info(u.normalize_path(endpoint.request_path))
  end

  def inc_index!
    @index += 1
  end

  SPECIAL_PATH_ELEMENTS = [
    Rack::App::Constants::PATH::APPLICATION,
    Rack::App::Constants::PATH::MOUNT_POINT
  ].freeze

  def clean_request_path_parts
    @request_path_parts - SPECIAL_PATH_ELEMENTS
  end

end

Version data entries

44 entries across 44 versions & 2 rubygems

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