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.



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

#controllerObject (readonly)

Return the controller specific configuration object.



177
178
179
# File 'lib/super_settings/configuration.rb', line 177

def controller
  @controller
end

#modelObject (readonly)

Return the model specific configuration object.



174
175
176
# File 'lib/super_settings/configuration.rb', line 174

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.



181
182
183
# File 'lib/super_settings/configuration.rb', line 181

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.



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