Class: Racket::Settings::Controller
- Defined in:
- lib/racket/settings/controller.rb
Overview
Class for storing controller settings. This settings class will lookup settings further up in the inheritance chain and will use the application settings as a final fallback.
Instance Method Summary collapse
-
#fetch(key, default = nil) ⇒ Object
Fetches settings from the current object.
-
#initialize(owner, defaults = {}) ⇒ Controller
constructor
A new instance of Controller.
Methods inherited from Base
default_value, #delete, #present?, setting, #store
Constructor Details
#initialize(owner, defaults = {}) ⇒ Controller
Returns a new instance of Controller.
27 28 29 30 |
# File 'lib/racket/settings/controller.rb', line 27 def initialize(owner, defaults = {}) super(defaults) @owner = owner end |
Instance Method Details
#fetch(key, default = nil) ⇒ Object
Fetches settings from the current object. If the setting cannot be found in the current object, the objects class/superclass will be queried. If all controller classes in the inheritance chain has been queried, the application settings will be used as a final fallback.
36 37 38 39 40 41 42 43 44 |
# File 'lib/racket/settings/controller.rb', line 36 def fetch(key, default = nil) return @custom[key] if @custom.key?(key) parent = @owner.is_a?(Class) ? @owner.superclass : @owner.class return @owner.context.application_settings.fetch(key, default) if @owner == ::Racket::Controller return parent.context.application_settings.fetch(key, default) if parent == ::Racket::Controller parent.settings.fetch(key, default) end |