Sha256: 0c71ac499eb51d0b9a8532c3092491c354cf805f07197cf4e5c11ddf30f37992

Contents?: true

Size: 546 Bytes

Versions: 4

Compression:

Stored size: 546 Bytes

Contents

require "erb"
require "yaml"

module KingKonf
  class ConfigFileLoader
    def initialize(config)
      @config = config
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
king_konf-1.0.0 lib/king_konf/config_file_loader.rb
king_konf-0.3.7 lib/king_konf/config_file_loader.rb
king_konf-0.3.6 lib/king_konf/config_file_loader.rb
king_konf-0.3.5 lib/king_konf/config_file_loader.rb