Module: Brainstem
- Defined in:
- lib/brainstem.rb,
lib/brainstem/cli.rb,
lib/brainstem/version.rb,
lib/brainstem/api_docs.rb,
lib/brainstem/dsl/field.rb,
lib/brainstem/preloader.rb,
lib/brainstem/presenter.rb,
lib/brainstem/test_helpers.rb,
lib/brainstem/time_classes.rb,
lib/brainstem/api_docs/atlas.rb,
lib/brainstem/dsl/base_block.rb,
lib/brainstem/concerns/lookup.rb,
lib/brainstem/dsl/association.rb,
lib/brainstem/dsl/conditional.rb,
lib/brainstem/api_docs/builder.rb,
lib/brainstem/dsl/fields_block.rb,
lib/brainstem/api_docs/endpoint.rb,
lib/brainstem/api_docs/resolver.rb,
lib/brainstem/concerns/optional.rb,
lib/brainstem/dsl/configuration.rb,
lib/brainstem/api_docs/presenter.rb,
lib/brainstem/controller_methods.rb,
lib/brainstem/api_docs/controller.rb,
lib/brainstem/api_docs/exceptions.rb,
lib/brainstem/presenter_validator.rb,
lib/brainstem/cli/abstract_command.rb,
lib/brainstem/concerns/formattable.rb,
lib/brainstem/presenter_collection.rb,
lib/brainstem/concerns/presenter_dsl.rb,
lib/brainstem/dsl/associations_block.rb,
lib/brainstem/dsl/conditionals_block.rb,
lib/brainstem/concerns/controller_dsl.rb,
lib/brainstem/search_unavailable_error.rb,
lib/brainstem/api_docs/sinks/stdout_sink.rb,
lib/brainstem/concerns/error_presentation.rb,
lib/brainstem/api_docs/abstract_collection.rb,
lib/brainstem/api_docs/endpoint_collection.rb,
lib/brainstem/api_docs/sinks/abstract_sink.rb,
lib/brainstem/api_docs/presenter_collection.rb,
lib/brainstem/cli/generate_api_docs_command.rb,
lib/brainstem/api_docs/controller_collection.rb,
lib/brainstem/query_strategies/base_strategy.rb,
lib/brainstem/query_strategies/filter_or_search.rb,
lib/brainstem/concerns/inheritable_configuration.rb,
lib/brainstem/query_strategies/filter_and_search.rb,
lib/brainstem/api_docs/formatters/markdown/helper.rb,
lib/brainstem/concerns/controller_param_management.rb,
lib/brainstem/api_docs/formatters/abstract_formatter.rb,
lib/brainstem/api_docs/introspectors/rails_introspector.rb,
lib/brainstem/api_docs/introspectors/abstract_introspector.rb,
lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb,
lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb,
lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb,
lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb,
lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb
Overview
Responsible for formatting each endpoint.
Defined Under Namespace
Modules: ApiDocs, CLI, Concerns, ControllerMethods, DSL, QueryStrategies, TestHelpers Classes: Cli, Preloader, Presenter, PresenterCollection, PresenterValidator, SearchUnavailableError
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.add_presenter_class(presenter_class, namespace, *klasses) ⇒ Object
Helper method to quickly add presenter classes that are in a namespace.
-
.default_namespace ⇒ String
The namespace that will be used by Brainstem.presenter_collection and Brainstem.add_presenter_class if none is given or implied.
-
.default_namespace=(namespace) ⇒ String
Sets Brainstem.default_namespace to a new value.
-
.logger ⇒ Logger
The Brainstem logger.
-
.logger=(logger) ⇒ Logger
Sets a new Brainstem logger.
-
.presenter_collection(namespace = nil) ⇒ PresenterCollection
The PresenterCollection for the given namespace.
-
.reset! ⇒ Object
Reset all PresenterCollection’s Presenters, clear the known collections, and reset the default namespace.
Class Method Details
.add_presenter_class(presenter_class, namespace, *klasses) ⇒ Object
Helper method to quickly add presenter classes that are in a namespace. For example, add_presenter_class(Api::V1::UserPresenter, “User”) would add UserPresenter to the PresenterCollection for the :v1 namespace as the presenter for the User class.
37 38 39 |
# File 'lib/brainstem.rb', line 37 def self.add_presenter_class(presenter_class, namespace, *klasses) presenter_collection(namespace).add_presenter_class(presenter_class, *klasses) end |
.default_namespace ⇒ String
The namespace that will be used by presenter_collection and add_presenter_class if none is given or implied.
20 21 22 |
# File 'lib/brainstem.rb', line 20 def self.default_namespace @default_namespace || "none" end |
.default_namespace=(namespace) ⇒ String
Sets default_namespace to a new value.
14 15 16 |
# File 'lib/brainstem.rb', line 14 def self.default_namespace=(namespace) @default_namespace = namespace end |
.logger ⇒ Logger
Returns The Brainstem logger. If Rails is loaded, defaults to the Rails logger. If Rails is not loaded, defaults to a STDOUT logger.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/brainstem.rb', line 42 def self.logger @logger ||= begin if defined?(Rails) Rails.logger else require "logger" Logger.new(STDOUT) end end end |
.logger=(logger) ⇒ Logger
Sets a new Brainstem logger.
56 57 58 |
# File 'lib/brainstem.rb', line 56 def self.logger=(logger) @logger = logger end |
.presenter_collection(namespace = nil) ⇒ PresenterCollection
Returns the PresenterCollection for the given namespace.
26 27 28 29 30 |
# File 'lib/brainstem.rb', line 26 def self.presenter_collection(namespace = nil) namespace ||= default_namespace @presenter_collection ||= {} @presenter_collection[namespace.to_s.downcase] ||= PresenterCollection.new end |
.reset! ⇒ Object
Reset all PresenterCollection’s Presenters, clear the known collections, and reset the default namespace. This is mostly intended for resetting between tests.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/brainstem.rb', line 62 def self.reset! if @presenter_collection @presenter_collection.each do |namespace, collection| collection.presenters.each do |klass, presenter| presenter.reset! if presenter.respond_to?(:reset!) end end end Brainstem::Presenter.reset! Brainstem::Presenter.reset_configuration! @presenter_collection = {} @default_namespace = nil end |