Class: SimpleConf::Loader
- Inherits:
-
Object
- Object
- SimpleConf::Loader
- Defined in:
- lib/simple-conf/loader.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass) ⇒ Loader
constructor
A new instance of Loader.
- #path ⇒ Object
- #run ⇒ Object
- #yaml_file ⇒ Object
Constructor Details
#initialize(klass) ⇒ Loader
Returns a new instance of Loader.
9 10 11 |
# File 'lib/simple-conf/loader.rb', line 9 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/simple-conf/loader.rb', line 7 def klass @klass end |
Instance Method Details
#path ⇒ Object
27 28 29 30 31 |
# File 'lib/simple-conf/loader.rb', line 27 def path class_name = klass.name.downcase.split("::").last "./config/#{class_name}.yml" end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple-conf/loader.rb', line 13 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_file ⇒ Object
33 34 35 36 |
# File 'lib/simple-conf/loader.rb', line 33 def yaml_file content = File.open(path).read YAML.load(ERB.new(content).result) end |