Class: KingKonf::ConfigFileLoader
- Inherits:
-
Object
- Object
- KingKonf::ConfigFileLoader
- Defined in:
- lib/king_konf/config_file_loader.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ ConfigFileLoader
constructor
A new instance of ConfigFileLoader.
- #load_file(path, environment = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ ConfigFileLoader
Returns a new instance of ConfigFileLoader.
6 7 8 |
# File 'lib/king_konf/config_file_loader.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#load_file(path, environment = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/king_konf/config_file_loader.rb', line 10 def load_file(path, environment = nil) # First, load the ERB template from disk. template = ERB.new(File.new(path).read) data = YAML.load(template.result(binding)) # Grab just the config for the environment, if specified. data = data.fetch(environment) unless environment.nil? data.each do |variable, value| @config.set(variable, value) end end |