Class: YARD::Server::Router

Inherits:
Object
  • Object
show all
Includes:
Commands, StaticCaching
Defined in:
lib/yard/server/router.rb

Overview

Since:

  • 0.6.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StaticCaching

#check_static_cache

Constructor Details

#initialize(adapter) ⇒ Router

Returns a new instance of Router.

Since:

  • 0.6.0



11
12
13
# File 'lib/yard/server/router.rb', line 11

def initialize(adapter)
  self.adapter = adapter
end

Instance Attribute Details

#adapterObject

Since:

  • 0.6.0



9
10
11
# File 'lib/yard/server/router.rb', line 9

def adapter
  @adapter
end

#requestObject

Since:

  • 0.6.0



7
8
9
# File 'lib/yard/server/router.rb', line 7

def request
  @request
end

Instance Method Details

#call(request) ⇒ Object

Since:

  • 0.6.0



15
16
17
18
19
20
21
22
# File 'lib/yard/server/router.rb', line 15

def call(request)
  self.request = request
  if result = (check_static_cache || route)
    result
  else
    StaticFileCommand.new(adapter.options).call(request)
  end
end

#docs_prefixObject

Since:

  • 0.6.0



24
# File 'lib/yard/server/router.rb', line 24

def docs_prefix; 'docs' end

#list_prefixObject

Since:

  • 0.6.0



25
# File 'lib/yard/server/router.rb', line 25

def list_prefix; 'list' end

#parse_library_from_path(paths) ⇒ Array(LibraryVersion, Array<String>)

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

Returns:

  • (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.

Since:

  • 0.6.0



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/yard/server/router.rb', line 31

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]
    paths.shift
    if library = libs.find {|l| l.version == paths.first }
      paths.shift
    else # use the last lib in the list
      library = libs.last
    end
  end
  [library, paths]
end

#search_prefixObject

Since:

  • 0.6.0



26
# File 'lib/yard/server/router.rb', line 26

def search_prefix; 'search' end