Class: Stringex::Configuration::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/stringex/configuration/configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Configurator

Returns a new instance of Configurator.


6
7
8
9
10
11
12
# File 'lib/stringex/configuration/configurator.rb', line 6

def initialize(klass)
  @klass = klass

  self.klass.valid_configuration_details.each do |name|
    define_instance_method_for_configuration_wrapper name
  end
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass


4
5
6
# File 'lib/stringex/configuration/configurator.rb', line 4

def klass
  @klass
end

Instance Method Details

#define_instance_method_for_configuration_wrapper(name) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'lib/stringex/configuration/configurator.rb', line 14

def define_instance_method_for_configuration_wrapper(name)
  name = name.respond_to?(:intern) ? name.intern : name
  (class << self; self; end).instance_eval do
    define_method("#{name}=") do |value|
      customizations = klass.send(:system_wide_customizations)
      customizations[name] = value
    end
  end
end