lib/yard/server/router.rb in yard-0.9.5 vs lib/yard/server/router.rb in yard-0.9.6
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
module YARD
module Server
# A router class implements the logic used to recognize a request for a specific
# URL and run specific {Commands::Base commands}.
#
@@ -50,15 +51,12 @@
#
# @param [Adapter Dependent] request the request object
# @return [Array(Numeric,Hash,Array)] the Rack-style server response data
def call(request)
self.request = request
- if result = (check_static_cache || route)
- result
- else
- RootRequestCommand.new(adapter.options).call(request)
- end
+ result = check_static_cache || route
+ result ? result : RootRequestCommand.new(adapter.options).call(request)
end
# @group Route Prefixes
# @return [String] the URI prefix for all object documentation requests
@@ -78,14 +76,17 @@
# @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.
def parse_library_from_path(paths)
return [adapter.libraries.values.first.first, paths] if adapter.options[:single_library]
- library, paths = nil, paths.dup
- if libs = adapter.libraries[paths.first]
+ library = nil
+ paths = paths.dup
+ libs = adapter.libraries[paths.first]
+ if libs
paths.shift
- if library = libs.find {|l| l.version == paths.first }
+ 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
@@ -103,20 +104,20 @@
# @return [nil] if no route is matched
def route(path = request.path_info)
path = path.gsub(%r{//+}, '/').gsub(%r{^/|/$}, '')
return route_index if path.empty? || path == docs_prefix
case path
- when /^(#{docs_prefix}|#{list_prefix}|#{search_prefix}|#{static_prefix})(\/.*|$)/
+ when %r{^(#{docs_prefix}|#{list_prefix}|#{search_prefix}|#{static_prefix})(/.*|$)}
prefix = $1
paths = $2.gsub(%r{^/|/$}, '').split('/')
library, paths = *parse_library_from_path(paths)
return unless library
return case prefix
- when docs_prefix; route_docs(library, paths)
- when list_prefix; route_list(library, paths)
- when search_prefix; route_search(library, paths)
- when static_prefix; route_static(library, paths)
- end
+ when docs_prefix; route_docs(library, paths)
+ when list_prefix; route_list(library, paths)
+ when search_prefix; route_search(library, paths)
+ when static_prefix; route_static(library, paths)
+ end
end
nil
end
# Routes requests from {#docs_prefix} and calls the appropriate command