class YARD::Server::RackMiddleware

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

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

@example Using the RackMiddleware in a Rack application

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

Public Class Methods

new(app, opts = {}) click to toggle source

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

@param app the next Rack middleware in the stack @option opts [Hash{String=>Array<LibraryVersion>}] :libraries ({})

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

@option opts [Hash] :options ({}) a list of options to pass to the adapter.

See {Adapter#options} for a list.

@option opts [Hash] :server_options ({}) a list of options to pass to the server.

See {Adapter#server_options} for a list.
# 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

Public Instance Methods

call(env) click to toggle source
# 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