class Brainstem::ApiDocs::Introspectors::AbstractIntrospector

Public Class Methods

with_loaded_environment(options = {}) click to toggle source

Returns a new instance of the introspector with the environment loaded, ready for introspection.

@param [Hash] options arguments to pass on to the instance @return [AbstractIntrospector] the loaded instance

# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 18
def self.with_loaded_environment(options = {})
  new(options).tap(&:load_environment!)
end

Public Instance Methods

controllers() click to toggle source

Override to return a collection of all controller classes.

@return [Array<Class>] all controller classes to document

# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 25
def controllers
  raise NotImplementedError
end
presenters() click to toggle source

Override to return a collection of all presenter classes.

@return [Array<Class>] all presenter classes to document

# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 32
def presenters
  raise NotImplementedError
end
routes() click to toggle source

Override to return a collection of hashes with the minimum following keys:

+:path+ - the relative path (i.e. the endpoint)
+:controller+ - the managing controller
+:action+ - the managing action
+:http_method+ - an array of the HTTP methods this route is available on.
# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 44
def routes
  raise NotImplementedError
end
valid?() click to toggle source

Provides both a sanity check to ensure that output confirms to interface and also confirms that there is actually something to generate docs for.

@return [Boolean] Whether the Introspector is valid

# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 53
def valid?
  valid_controllers? && valid_presenters? && valid_routes?
end
valid_options() click to toggle source
# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 9
def valid_options
  [ ]
end

Private Instance Methods

load_environment!() click to toggle source

Loads the host application environment. @api private

# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 67
def load_environment!
  raise NotImplementedError
end
valid_controllers?() click to toggle source
# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 71
def valid_controllers?
  controllers.is_a?(Array) &&
    controllers.count > 0 &&
    controllers.all? {|c| c.class == Class }
end
valid_presenters?() click to toggle source
# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 77
def valid_presenters?
  presenters.is_a?(Array) &&
    presenters.all? {|p| p.class == Class }
end
valid_routes?() click to toggle source
# File lib/brainstem/api_docs/introspectors/abstract_introspector.rb, line 82
def valid_routes?
  routes.is_a?(Array) &&
    routes.count > 0 &&
    routes.all? do |r|
      r.is_a?(Hash) &&
        ([:path, :controller, :action, :http_methods] - r.keys).empty?
    end
end