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.
205 206 207 208 209 210 |
# File 'lib/super_settings/configuration.rb', line 205 def initialize @model = Model.new @controller = Controller.new @deferred_configs = [] @called = false end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Return the controller specific configuration object.
199 200 201 |
# File 'lib/super_settings/configuration.rb', line 199 def controller @controller end |
#model ⇒ Object (readonly)
Return the model specific configuration object.
196 197 198 |
# File 'lib/super_settings/configuration.rb', line 196 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.
203 204 205 |
# File 'lib/super_settings/configuration.rb', line 203 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.
229 230 231 232 233 234 |
# File 'lib/super_settings/configuration.rb', line 229 def call @called = true 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. If the deferred configuration has already been run (i.e. the application has finished initializing), the block is called immediately.
218 219 220 221 222 223 224 |
# File 'lib/super_settings/configuration.rb', line 218 def defer(&block) if @called block.call(self) else @deferred_configs << block end end |