class Brainstem::ApiDocs::Builder

Attributes

args_for_atlas[W]

Allows passing args to the atlas if - for example - you are specifying match terms for the allowable controller set.

args_for_introspector[W]

Allows passing args to the introspector if - for example - you are using a custom base controller class.

atlas[RW]

Holds a reference to the constructed atlas.

atlas_method[W]

Allows setting the introspector_method if - for example - you are using an alternative formatter and the requisite information is not present in the Endpoint objects.

introspector[RW]

Holds a reference to the constructed introspector.

introspector_method[W]

Allows setting the introspector_method if - for example - you are using Brainstem on a Sinatra app and you need to customize how lookups for presenters, controllers, and routes are performed.

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Proc] :introspector_method Proc of arity one that

returns an Introspector (an object that introspects into
the host application, seeking its routes, controllers, and
presenters).

@option options [Hash] :args_for_introspector Additional arguments to

be passed to the introspector on creation.

@option options [Hash] :args_for_atlas Additional arguments to be passed

to the atlas on creation.

@option options [Proc,Object] :introspector_method A method that

returns an introspector when called.

@option options [Proc,Object] :atlas_method A method that returns an Atlas-like

object when called.

@see Brainstem::ApiDocs::Introspectors::AbstractIntrospector @see Brainstem::ApiDocs::Introspectors::RailsIntrospector

Calls superclass method Brainstem::Concerns::Optional::new
# File lib/brainstem/api_docs/builder.rb, line 47
def initialize(options = {})
  super

  build_introspector!
  build_atlas!
end

Public Instance Methods

args_for_atlas() click to toggle source

Arguments to be passed to the atlas on creation.

@see Brainstem::ApiDocs::Atlas

# File lib/brainstem/api_docs/builder.rb, line 89
def args_for_atlas
  @args_for_atlas ||= {}
end
args_for_introspector() click to toggle source

Arguments to be passed to the introspector on creation.

@see Brainstem::ApiDocs::Introspectors::AbstractIntrospector @see Brainstem::ApiDocs::Introspectors::RailsIntrospector

# File lib/brainstem/api_docs/builder.rb, line 74
def args_for_introspector
  @args_for_introspector ||= {}
end
atlas_method() click to toggle source

A proc of arity 1..2 which takes an introspector and optional options, and which returns a new Atlas.

Passed an introspector.

@return [Proc] a method to return an atlas

# File lib/brainstem/api_docs/builder.rb, line 136
def atlas_method
  @atlas_method ||= Atlas.method(:new)
end
build_atlas!() click to toggle source

Builds an atlas.

# File lib/brainstem/api_docs/builder.rb, line 64
def build_atlas!
  self.atlas = atlas_method.call(introspector, args_for_atlas)
end
build_introspector!() click to toggle source

Builds an introspector.

# File lib/brainstem/api_docs/builder.rb, line 57
def build_introspector!
  self.introspector = introspector_method.call(args_for_introspector)
end
introspector_method() click to toggle source

A method which returns the introspector which extracts information about the Brainstem-powered API from the host application.

Stored as a proc because it's impossible to inject an instantiated object and have it receive args from this class. This is less important in this specific circumstance but is kept for uniformity with atlas_method.

@return [Proc] a proc of arity 1 which takes an options hash and

returns an introspector
# File lib/brainstem/api_docs/builder.rb, line 111
def introspector_method
  @introspector_method ||=
    Introspectors::RailsIntrospector.method(:with_loaded_environment)
end
valid_options() click to toggle source
# File lib/brainstem/api_docs/builder.rb, line 19
def valid_options
  [
    :introspector_method,
    :atlas_method,

    :args_for_introspector,
    :args_for_atlas
  ]
end