File: configurator.rb

package info (click to toggle)
ruby-stringex 2.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,220 kB
  • sloc: ruby: 3,749; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Stringex
  module Configuration
    class Configurator
      attr_accessor :klass

      def initialize(klass)
        @klass = klass

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

      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
    end
  end
end