Class: SuperSettings::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#controllerObject (readonly)

Return the controller specific configuration object.



199
200
201
# File 'lib/super_settings/configuration.rb', line 199

def controller
  @controller
end

#modelObject (readonly)

Return the model specific configuration object.



196
197
198
# File 'lib/super_settings/configuration.rb', line 196

def model
  @model
end

#refresh_intervalObject

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

#callObject

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