Class YARD::Server::Router
In: lib/yard/server/router.rb
Parent: Object

A router class implements the logic used to recognize a request for a specific URL and run specific {Commands::Base commands}.

Subclassing Notes

To create a custom router, subclass this class and pass it into the adapter options through {Adapter#initialize} or by directly modifying {Adapter#router}.

The most general customization is to change the URL prefixes recognized by routing, which can be done by overriding {docs_prefix}, {list_prefix} and {search_prefix}.

Implementing Custom Caching

By default, the Router class performs static disk-based caching on all requests through the +check_static_cache+. To override this behaviour, or create your own caching mechanism, mixin your own custom module with this method implemented as per {StaticCaching#check_static_cache}.

@example Creating a subclassed router

  # Adds 'my' to all routing prefixes
  class MyRouter < YARD::Server::Router
    def docs_prefix; 'mydocs' end
    def list_prefix; 'mylist' end
    def search_prefix; 'mysearch' end
  end

  # Using it:
  WebrickAdapter.new(libraries, :router => MyRouter).start

Methods

Included Modules

StaticCaching Commands

Attributes

adapter  [RW]  @return [Adapter] the adapter used by the router
request  [RW]  @return [Adapter Dependent] the request data coming in with the routing

Public Class methods

Creates a new router for a specific adapter

@param [Adapter] adapter the adapter to route requests to

Public Instance methods

Perform routing on a specific request, serving the request as a static file through {Commands::StaticFileCommand} if no route is found.

@param [Adapter Dependent] request the request object @return [Array(Numeric,Hash,Array)] the Rack-style server response data

@return [String] the URI prefix for all object documentation requests

@return [String] the URI prefix for all class/method/file list requests

@return [Array(LibraryVersion, Array<String>)] the library followed

  by the rest of the path components in the request path. LibraryVersion
  will be nil if no matching library was found.

@return [String] the URI prefix for all search requests

Protected Instance methods

Adds extra :library/:path option keys to the adapter options. Use this method when passing options to a command.

@param (see route_docs) @return [Hash] finalized options

Performs routing algorithm to find which prefix is called, first parsing out library name/version information.

@return [Array(Numeric,Hash,Array<String>)] the Rack-style response @return [nil] if no route is matched

Routes requests from {docs_prefix} and calls the appropriate command @param [LibraryVersion] library the library to route for @param [Array<String>] paths path components (split by ’/’) @return (see route)

Routes for the index of a library / multiple libraries @return (see route)

Routes requests from {list_prefix} and calls the appropriate command @param (see route_docs) @return (see route_docs)

Routes requests from {search_prefix} and calls the appropriate command @param (see route_docs) @return (see route_docs)

[Validate]