Class: SimpleConf::Loader

Inherits:
Struct
  • Object
show all
Defined in:
lib/simple-conf/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



6
7
8
# File 'lib/simple-conf/loader.rb', line 6

def klass
  @klass
end

Instance Method Details

#config_file_nameObject



25
26
27
28
29
# File 'lib/simple-conf/loader.rb', line 25

def config_file_name
  klass.respond_to?(:config_file_name) ?
    klass.config_file_name :
    "#{klass.name.downcase.split("::").last}.yml"
end

#pathObject



21
22
23
# File 'lib/simple-conf/loader.rb', line 21

def path
  "./config/#{config_file_name}"
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple-conf/loader.rb', line 7

def run
  yaml_file.each_pair do |key, value|
    set(key, value)
  end

  yaml_file.fetch(Rails.env, {}).each_pair do |key, value|
    set(key, value)
  end if rails_environment_defined?

  yaml_file.fetch(klass.env, {}).each_pair do |key, value|
    set(key, value)
  end if klass.respond_to?(:env)
end

#yaml_fileObject



31
32
33
34
# File 'lib/simple-conf/loader.rb', line 31

def yaml_file
  content = File.open(path).read
  YAML.load(ERB.new(content).result)
end