Class: YARD::Server::Router
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Commands ,
StaticCaching
|
|
Inherits: | Object |
Defined in: | lib/yard/server/router.rb |
Overview
A router class implements the logic used to recognize a request for a specific URL and run specific 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, #static_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.
Route Prefixes
Routing Methods
Class Method Summary
-
.new(adapter) ⇒ Router
constructor
Creates a new router for a specific adapter.
Instance Attribute Summary
Instance Method Summary
-
#call(request) ⇒ Array(Numeric,Hash,Array)
Perform routing on a specific request, serving the request as a static file through
Commands::RootRequestCommand
if no route is found.
StaticCaching
- Included
#check_static_cache | Called by a router to return the cached object. |
Constructor Details
.new(adapter) ⇒ Router
Creates a new router for a specific adapter
Instance Attribute Details
#adapter ⇒ Adapter (rw)
# File 'lib/yard/server/router.rb', line 40
attr_accessor :adapter
#request ⇒ Adapter Dependent
(rw)
# File 'lib/yard/server/router.rb', line 37
attr_accessor :request
Instance Method Details
#call(request) ⇒ Array(Numeric
,Hash,Array)
Perform routing on a specific request, serving the request as a static
file through Commands::RootRequestCommand
if no route is found.
#docs_prefix ⇒ String
# File 'lib/yard/server/router.rb', line 63
def docs_prefix; 'docs' end
#list_prefix ⇒ String
# File 'lib/yard/server/router.rb', line 66
def list_prefix; 'list' end
#parse_library_from_path(paths) ⇒ Array(LibraryVersion, Array<String>)
# File 'lib/yard/server/router.rb', line 79
def parse_library_from_path(paths) return [adapter.libraries.values.first.first, paths] if adapter. [:single_library] library = nil paths = paths.dup libs = adapter.libraries[paths.first] if libs paths.shift library = libs.find {|l| l.version == paths.first } if library request.version_supplied = true if request paths.shift else # use the last lib in the list request.version_supplied = false if request library = libs.last end end [library, paths] end
#search_prefix ⇒ String
# File 'lib/yard/server/router.rb', line 69
def search_prefix; 'search' end
#static_prefix ⇒ String
# File 'lib/yard/server/router.rb', line 72
def static_prefix; 'static' end