Sha256: 49e8a4ae110a799550d8b406d7a3519156e75a22a4755018faa0fdae3cd52eb5

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

class Rack::App::Router::Base

  def call(env)

    request_method= env[::Rack::App::Constants::ENV::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

2 entries across 2 versions & 1 rubygems

Version Path
rack-app-5.4.0 lib/rack/app/router/base.rb
rack-app-5.3.2 lib/rack/app/router/base.rb