Class: Brainstem::ApiDocs::Introspectors::RailsIntrospector

Inherits:
AbstractIntrospector show all
Defined in:
lib/brainstem/api_docs/introspectors/rails_introspector.rb

Instance Method Summary collapse

Methods inherited from AbstractIntrospector

#valid?, with_loaded_environment

Methods included from Concerns::Optional

#initialize

Instance Method Details

#base_applicationClass

Returns the alternate application class or defaults to Rails.application

Returns:

  • (Class)

    The base application class



52
53
54
# File 'lib/brainstem/api_docs/introspectors/rails_introspector.rb', line 52

def base_application
  base_application_class.present? ? base_application_class.constantize : ::Rails.application
end

#controllersArray<Class>

Returns a list of controllers that descend from the base controller class.

Returns:

  • (Array<Class>)

    an array of descendant classes



43
44
45
# File 'lib/brainstem/api_docs/introspectors/rails_introspector.rb', line 43

def controllers
  base_controller_class.constantize.descendants
end

#load_environment!Object

Loads ./config/environment.rb (by default) and eager loads all classes (otherwise #descendants returns an empty set).



16
17
18
19
20
21
22
23
24
25
# File 'lib/brainstem/api_docs/introspectors/rails_introspector.rb', line 16

def load_environment!
  load rails_environment_file unless env_already_loaded?
  base_application.eager_load!

  validate!
rescue LoadError => e
  raise IncorrectIntrospectorForAppException,
    "Hosting app does not appear to be a Rails app." +
    "You may have to manually specify an Introspector (#{e.message})."
end

#presentersArray<Class>

Returns a list of presenters that descend from the base presenter class.

Returns:

  • (Array<Class>)

    an array of descendant classes



33
34
35
# File 'lib/brainstem/api_docs/introspectors/rails_introspector.rb', line 33

def presenters
  base_presenter_class.constantize.descendants
end

#routesArray<Hash>

Returns an array of hashes describing the endpoints of the application. See routes_method for the keys of those hashes.

Returns:

  • (Array<Hash>)

    each route defined on the hosting app

See Also:

  • #routes_method


63
64
65
# File 'lib/brainstem/api_docs/introspectors/rails_introspector.rb', line 63

def routes
  routes_method.call
end