Class: YARD::Server::RackMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/server/rack_adapter.rb

Overview

Note:

You must pass a :libraries option to the RackMiddleware via #use. To read about how to return a list of libraries, see LibraryVersion or look at the example below.

This class wraps the RackAdapter into a Rack-compatible middleware. See #initialize for a list of options to pass via Rack’s #use method.

Examples:

Using the RackMiddleware in a Rack application

libraries = {:mylib => [YARD::Server::LibraryVersion.new('mylib', nil, '/path/to/.yardoc')]}
use YARD::Server::RackMiddleware, :libraries => libraries

Since:

  • 0.6.0

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ RackMiddleware

Creates a new Rack-based middleware for serving YARD documentation.

Parameters:

  • app

    the next Rack middleware in the stack

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :libraries (Hash{String=>Array<LibraryVersion>}) — default: {}

    the map of libraries to serve through the adapter. This option is required.

  • :options (Hash) — default: {}

    a list of options to pass to the adapter. See Adapter#options for a list.

  • :server_options (Hash) — default: {}

    a list of options to pass to the server. See Adapter#server_options for a list.

Since:

  • 0.6.0



35
36
37
38
39
# File 'lib/yard/server/rack_adapter.rb', line 35

def initialize(app, opts = {})
  args = [opts[:libraries] || {}, opts[:options] || {}, opts[:server_options] || {}]
  @app = app
  @adapter = RackAdapter.new(*args)
end

Instance Method Details

#call(env) ⇒ Object

Since:

  • 0.6.0



41
42
43
44
45
46
47
48
# File 'lib/yard/server/rack_adapter.rb', line 41

def call(env)
  status, headers, body = *@adapter.call(env)
  if status == 404
    @app.call(env)
  else
    [status, headers, body]
  end
end