Sha256: 941d368f263ef1255505375437a04c60d6548998b086cc4825e2cecbf1578098

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

class Rack::App::Router::Base

  def call(env)

    request_method= env[Rack::REQUEST_METHOD]
    path_info= env[Rack::App::Constants::ENV::PATH_INFO]

    context = fetch_context(request_method, path_info)
    return unless context.is_a?(Hash) and not context[:app].nil?

    context[:app].call(env)
  end


  def endpoints
    @endpoints ||= []
  end

  def register_endpoint!(endpoint)
    endpoints.push(endpoint)
    compile_endpoint!(endpoint)
    return endpoint
  end

  def reset
    clean_routes!
    compile_registered_endpoints!
  end

  protected

  def compile_endpoint!(endpoint)
    raise(NotImplementedError)
  end

  def clean_routes!
    raise(NotImplementedError)
  end

  def compile_registered_endpoints!
    raise(NotImplementedError)
  end

  def fetch_context(request_method, request_path)
    raise(NotImplementedError)
  end

  def as_app(endpoint_or_app)
    if endpoint_or_app.respond_to?(:to_app)
      endpoint_or_app.to_app
    else
      endpoint_or_app
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-app-5.3.1 lib/rack/app/router/base.rb