Module: Brainstem
- Defined in:
- lib/brainstem.rb,
lib/brainstem/engine.rb,
lib/brainstem/version.rb,
lib/brainstem/presenter.rb,
lib/brainstem/test_helpers.rb,
lib/brainstem/time_classes.rb,
lib/brainstem/association_field.rb,
lib/brainstem/controller_methods.rb,
lib/brainstem/presenter_collection.rb,
lib/brainstem/search_unavailable_error.rb
Overview
The Brainstem module itself contains a default_namespace class attribute and a few helpers that make managing PresenterCollections and their corresponding namespaces easier.
Defined Under Namespace
Modules: ControllerMethods, TestHelpers Classes: AssociationField, Engine, Presenter, PresenterCollection, SearchUnavailableError
Constant Summary collapse
- VERSION =
"0.2.5"
Class Method Summary collapse
-
.add_presenter_class(presenter_class, *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.
-
.namespace_of(klass) ⇒ String
The name of the module containing the passed-in class.
-
.presenter_collection(namespace = nil) ⇒ PresenterCollection
The PresenterCollection for the given namespace.
Class Method Details
.add_presenter_class(presenter_class, *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.
32 33 34 |
# File 'lib/brainstem.rb', line 32 def self.add_presenter_class(presenter_class, *klasses) presenter_collection(namespace_of(presenter_class)).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.
17 18 19 |
# File 'lib/brainstem.rb', line 17 def self.default_namespace @default_namespace || "none" end |
.default_namespace=(namespace) ⇒ String
Sets default_namespace to a new value.
11 12 13 |
# File 'lib/brainstem.rb', line 11 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.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/brainstem.rb', line 44 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.
58 59 60 |
# File 'lib/brainstem.rb', line 58 def self.logger=(logger) @logger = logger end |
.namespace_of(klass) ⇒ String
Returns The name of the module containing the passed-in class.
38 39 40 41 |
# File 'lib/brainstem.rb', line 38 def self.namespace_of(klass) names = klass.to_s.split("::") names[-2] ? names[-2] : default_namespace end |
.presenter_collection(namespace = nil) ⇒ PresenterCollection
Returns the PresenterCollection for the given namespace.
23 24 25 26 27 |
# File 'lib/brainstem.rb', line 23 def self.presenter_collection(namespace = nil) namespace ||= default_namespace @presenter_collection ||= {} @presenter_collection[namespace.to_s.downcase] ||= PresenterCollection.new end |