Module: ObjectifyConfig

Defined in:
lib/objectify_config.rb,
lib/objectify_config/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configuration_files(*files) ⇒ Object



7
8
9
# File 'lib/objectify_config.rb', line 7

def configuration_files(*files)
  @configurations = files
end

.klass_name_for(config_file) ⇒ Object



38
39
40
# File 'lib/objectify_config.rb', line 38

def klass_name_for(config_file)
  "#{Pathname.new(config_file).basename.to_s.split('.')[0].camelize}Config"
end

.runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/objectify_config.rb', line 11

def run
  @configurations.flatten.each do |config_file|
    config_klass_name = klass_name_for(config_file)

    temp_class = Class.new do

      singleton_class.class_eval do
        Object.const_set("CONFIG_FILE", config_file)

        def method_missing(key)
          configuration_keys[key.to_sym]
        end

        def configuration_keys
          file_contents = YAML.load_file(CONFIG_FILE)

          file_contents.each_with_object({}) do |(h,k), result| 
            result[h.to_sym] = k 
          end
        end
      end
    end

    Object.const_set(config_klass_name, temp_class)
  end
end