Module: ARSettings::HasSettings

Defined in:
lib/arsettings/has_settings.rb

Instance Method Summary collapse

Instance Method Details

#has_setting(name, inner_options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/arsettings/has_settings.rb', line 4

def has_setting( name , inner_options={} , &block )
  @arsettings_package ||= ARSettings.default_class.package(self)
  instance = inner_options.delete :instance
  package = @arsettings_package
  package.add name , inner_options , &block
  definitions = lambda do |*args|
    define_method name        do       package.send name              end # getter
    define_method "#{name}="  do |arg| package.send "#{name}=" , arg  end # setter
    define_method "#{name}?"  do       package.send "#{name}?"        end # boolean-getter
  end
  (class << self ; self ; end).instance_eval(&definitions)
  definitions.call if instance
end