123456789_123456789_123456789_123456789_123456789_

Class: YARD::Server::Adapter Abstract

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/yard/server/adapter.rb

Overview

This class is abstract.

This class implements the bridge between the Router and the server backend for a specific server type. ::YARD implements concrete adapters for WEBrick and Rack respectively, though other adapters can be made for other server architectures.

Subclassing Notes

To create a concrete adapter class, implement the #start method to initiate the server backend.

Since:

  • 0.6.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(libs, opts = {}, server_opts = {}) ⇒ Adapter

Creates a new adapter object

Parameters:

Options Hash (opts):

  • :router (Class) — default: Router

    the router class to initialize as the adapter's router.

  • :caching (Boolean) — default: false

    whether or not caching is enabled

  • :single_library (Boolean) — default: false

    whether to server documentation for a single or multiple libraries (changes URL structure)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 71

def initialize(libs, opts = {}, server_opts = {})
  self.class.setup
  self.libraries = libs
  self.options = opts
  self.server_options = server_opts
  self.document_root = server_options[:DocumentRoot]
  self.router = (options[:router] || Router).new(self)
  options[:adapter] = self
  log.debug "Serving libraries using #{self.class}: #{libraries.keys.join(', ')}"
  log.debug "Caching on" if options[:caching]
  log.debug "Document root: #{document_root}" if document_root
end

Class Method Details

.setupvoid

Note:

If you subclass this method, make sure to call super.

This method returns an undefined value.

Performs any global initialization for the adapter.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 48

def self.setup
  Templates::Template.extra_includes |= [YARD::Server::DocServerHelper]
  Templates::Engine.template_paths |= [File.dirname(__FILE__) + '/templates']
end

.shutdownvoid

Note:

If you subclass this method, make sure to call super.

This method returns an undefined value.

Performs any global shutdown procedures for the adapter.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 56

def self.shutdown
  Templates::Template.extra_includes -= [YARD::Server::DocServerHelper]
  Templates::Engine.template_paths -= [File.dirname(__FILE__) + '/templates']
end

Instance Attribute Details

#document_rootString (rw)

Returns:

  • (String)

    the location where static files are located, if any. To set this field on initialization, pass :DocumentRoot to the server_opts argument in #initialize

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 27

attr_accessor :document_root

#librariesHash{String=>Array<LibraryVersion>} (rw)

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 32

attr_accessor :libraries

#optionsHash (rw)

Returns:

  • (Hash)

    options passed and processed by adapters. The actual options mostly depend on the adapters themselves.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 36

attr_accessor :options

#routerRouter (rw)

Returns:

  • (Router)

    the router object used to route URLs to commands

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 43

attr_accessor :router

#server_optionsHash (rw)

Returns:

  • (Hash)

    a set of options to pass to the server backend. Note that :DocumentRoot also sets the #document_root.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 40

attr_accessor :server_options

Instance Method Details

#add_library(library)

Adds a library to the #libraries mapping for a given library object.

Examples:

Adding a new library to an adapter

adapter.add_library LibraryVersion.new('mylib', '1.0', '/path/to/.yardoc')

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 88

def add_library(library)
  libraries[library.name] ||= []
  libraries[library.name] |= [library]
end

#start

This method is abstract.

Implement this method to connect your adapter to your server.

Raises:

  • (NotImplementedError)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/adapter.rb', line 95

def start
  raise NotImplementedError
end