Method: ActiveSettings::Config::Definition#initialize

Defined in:
lib/active_settings/config/definition.rb

#initialize(options = {}) ⇒ Definition

Configuration ‘definitions’ are metadata held in memory that add restriction and description to individual config entries.

By default ActiveSettings’ configuration machinery is open and ad-hoc: config items are just globally-accessible variables. They’re created when first mentioned and then available in all parts of the application. The definition mechanism is a way to place limits on that behavior. It allows you to protect a config entry, to specify the values it can take and to validate it when it changes. In the next update it will also allow you to declare that a config item is global or site-specific.

The actual defining is done by ActiveSettings::Config#define and usually in a block like this:

ActiveSettings::Config.configure do |config|
  config.namespace('users', :allow_change => true) do |users|
    users.define 'allow_password_reset?', :label => 'Allow password reset?'
  end
end

See the method documentation in ActiveSettings::Config for options and conventions.



27
28
29
30
31
32
# File 'lib/active_settings/config/definition.rb', line 27

def initialize(options={})
  [:empty, :default, :type, :label, :notes, :validate_with, :select_from, :allow_blank,
   :allow_change, :allow_display, :units, :definer].each do |attribute|
    instance_variable_set "@#{attribute}".to_sym, options[attribute]
  end
end