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

call docs_prefix final_options list_prefix new parse_library_from_path route route_docs route_index route_list route_search search_prefix

### 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

new(adapter)

Creates a new router for a specific adapter

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

### Public Instance methods

call(request)

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(Number,Hash,Array)] the Rack-style server response data

docs_prefix()

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

list_prefix()

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

parse_library_from_path(paths)

@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.

search_prefix()

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

### Protected Instance methods

final_options(library, paths)

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

route()

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

route_docs(library, paths)

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)

route_index()

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

route_list(library, paths)

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

route_search(library, paths)

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

[Validate]