Class: SuperSettings::Configuration
- Inherits:
-
Object
- Object
- SuperSettings::Configuration
- Includes:
- Singleton
- Defined in:
- lib/super_settings/configuration.rb
Overview
Configuration for the gem when run as a Rails engine. Default values and behaviors on the controller and model can be overridden with the configuration.
The configuration is a singleton instance.
Defined Under Namespace
Classes: Controller, Model
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Return the controller specific configuration object.
-
#model ⇒ Object
readonly
Return the model specific configuration object.
-
#refresh_interval ⇒ Object
Set the number of seconds that settings will be cached locally before the database is checked for updates.
Instance Method Summary collapse
-
#call ⇒ Object
private
Call the block deferred during initialization.
-
#defer(&block) ⇒ Object
private
Defer the execution of a block that will be yielded to with the config object.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
183 184 185 186 187 |
# File 'lib/super_settings/configuration.rb', line 183 def initialize @model = Model.new @controller = Controller.new @deferred_configs = [] end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Return the controller specific configuration object.
177 178 179 |
# File 'lib/super_settings/configuration.rb', line 177 def controller @controller end |
#model ⇒ Object (readonly)
Return the model specific configuration object.
174 175 176 |
# File 'lib/super_settings/configuration.rb', line 174 def model @model end |
#refresh_interval ⇒ Object
Set the number of seconds that settings will be cached locally before the database is checked for updates. Defaults to 5 seconds.
181 182 183 |
# File 'lib/super_settings/configuration.rb', line 181 def refresh_interval @refresh_interval end |
Instance Method Details
#call ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Call the block deferred during initialization.
201 202 203 204 205 |
# File 'lib/super_settings/configuration.rb', line 201 def call while (block = @deferred_configs.shift) block&.call(self) end end |
#defer(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defer the execution of a block that will be yielded to with the config object. This is needed in a Rails environment during initialization so that all the frameworks can load before loading the settings.
194 195 196 |
# File 'lib/super_settings/configuration.rb', line 194 def defer(&block) @deferred_configs << block end |