class Brainstem::ApiDocs::Builder
Attributes
Allows passing args to the atlas if - for example - you are specifying match terms for the allowable controller set.
Allows passing args to the introspector if - for example - you are using a custom base controller class.
Holds a reference to the constructed atlas.
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.
Holds a reference to the constructed introspector.
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
@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
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
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
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
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
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
Builds an introspector.
# File lib/brainstem/api_docs/builder.rb, line 57 def build_introspector! self.introspector = introspector_method.call(args_for_introspector) end
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
# File lib/brainstem/api_docs/builder.rb, line 19 def valid_options [ :introspector_method, :atlas_method, :args_for_introspector, :args_for_atlas ] end