Module: ARSettings::SettingsClass::ClassMethods

Defined in:
lib/arsettings/settings_class/class_methods.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)

:nodoc:



40
41
42
43
44
45
46
47
48
# File 'lib/arsettings/settings_class/class_methods.rb', line 40

def method_missing(name,*args) # :nodoc:
  if name =~ /\A[A-Z]/
    const_get name , *args
  elsif name.to_s !~ /=$/ || ( name.to_s =~ /=$/ && args.size == 1 )
    package(self).send name , *args
  else
    super
  end
end

Instance Method Details

#add(name, options = {}, &proc) ⇒ Object Also known as: has_setting

add a setting to the settings class, it will be packaged under the settings class itself

– FIXME: Document the options and proc



27
28
29
30
31
32
33
34
# File 'lib/arsettings/settings_class/class_methods.rb', line 27

def add( name , options={} , &proc )
  options = name if name.is_a? Hash
  if options[:package]
    package options.delete(:package)
  else
    package self
  end.add( name , options , &proc )
end

#package(name) ⇒ Object

get a Package (aka namespace or scope or group) to package settings together with

email_settings = Settings.package :email

email_settings.add :enabled , :default => false

ProfileSettings = Settings.package :profile_settings

ProfileSettings.add :enabled , :default => true



19
20
21
# File 'lib/arsettings/settings_class/class_methods.rb', line 19

def package(name)
  Packaged.instance self , name
end

#reset_allObject

:nodoc:



5
6
7
# File 'lib/arsettings/settings_class/class_methods.rb', line 5

def reset_all # :nodoc:
  Packaged.instances(self).each { |name,package| package.reset }
end