Class: Brainstem::ApiDocs::Builder

Inherits:
Object
  • Object
show all
Includes:
Concerns::Optional
Defined in:
lib/brainstem/api_docs/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder.

Parameters:

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

Options Hash (options):

  • :introspector_method (Proc)

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

  • :args_for_introspector (Hash)

    Additional arguments to be passed to the introspector on creation.

  • :args_for_atlas (Hash)

    Additional arguments to be passed to the atlas on creation.

  • :introspector_method (Proc, Object)

    A method that returns an introspector when called.

  • :atlas_method (Proc, Object)

    A method that returns an Atlas-like object when called.

See Also:



49
50
51
52
53
54
# File 'lib/brainstem/api_docs/builder.rb', line 49

def initialize(options = {})
  super

  build_introspector!
  build_atlas!
end

Instance Attribute Details

#args_for_atlasObject

Arguments to be passed to the atlas on creation.

See Also:



96
97
98
# File 'lib/brainstem/api_docs/builder.rb', line 96

def args_for_atlas
  @args_for_atlas ||= {}
end

#args_for_introspectorObject

Arguments to be passed to the introspector on creation.



79
80
81
# File 'lib/brainstem/api_docs/builder.rb', line 79

def args_for_introspector
  @args_for_introspector ||= {}
end

#atlasObject

Holds a reference to the constructed atlas.



164
165
166
# File 'lib/brainstem/api_docs/builder.rb', line 164

def atlas
  @atlas
end

#atlas_methodProc

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

Passed an introspector.

Returns:

  • (Proc)

    a method to return an atlas



148
149
150
# File 'lib/brainstem/api_docs/builder.rb', line 148

def atlas_method
  @atlas_method ||= Atlas.method(:new)
end

#introspectorObject

Holds a reference to the constructed introspector.



137
138
139
# File 'lib/brainstem/api_docs/builder.rb', line 137

def introspector
  @introspector
end

#introspector_methodProc

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.

Returns:

  • (Proc)

    a proc of arity 1 which takes an options hash and returns an introspector



120
121
122
123
# File 'lib/brainstem/api_docs/builder.rb', line 120

def introspector_method
  @introspector_method ||=
    Introspectors::RailsIntrospector.method(:with_loaded_environment)
end

Instance Method Details

#build_atlas!Object

Builds an atlas.



68
69
70
# File 'lib/brainstem/api_docs/builder.rb', line 68

def build_atlas!
  self.atlas = atlas_method.call(introspector, args_for_atlas)
end

#build_introspector!Object

Builds an introspector.



60
61
62
# File 'lib/brainstem/api_docs/builder.rb', line 60

def build_introspector!
  self.introspector = introspector_method.call(args_for_introspector)
end

#valid_optionsObject



20
21
22
23
24
25
26
27
28
# File 'lib/brainstem/api_docs/builder.rb', line 20

def valid_options
  [
    :introspector_method,
    :atlas_method,

    :args_for_introspector,
    :args_for_atlas
  ]
end