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