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:



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

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:



89
90
91
# File 'lib/brainstem/api_docs/builder.rb', line 89

def args_for_atlas
  @args_for_atlas ||= {}
end

#args_for_introspectorObject

Arguments to be passed to the introspector on creation.



74
75
76
# File 'lib/brainstem/api_docs/builder.rb', line 74

def args_for_introspector
  @args_for_introspector ||= {}
end

#atlasObject

Holds a reference to the constructed atlas.



150
151
152
# File 'lib/brainstem/api_docs/builder.rb', line 150

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



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

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

#introspectorObject

Holds a reference to the constructed introspector.



126
127
128
# File 'lib/brainstem/api_docs/builder.rb', line 126

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



111
112
113
114
# File 'lib/brainstem/api_docs/builder.rb', line 111

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

Instance Method Details

#build_atlas!Object

Builds an atlas.



64
65
66
# File 'lib/brainstem/api_docs/builder.rb', line 64

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

#build_introspector!Object

Builds an introspector.



57
58
59
# File 'lib/brainstem/api_docs/builder.rb', line 57

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

#valid_optionsObject



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

def valid_options
  [
    :introspector_method,
    :atlas_method,

    :args_for_introspector,
    :args_for_atlas
  ]
end