Sha256: b0d965c8efd1a5b485395379562ca41e09ee8b96bf5d16b4ce55fa1bf4338d93

Contents?: true

Size: 582 Bytes

Versions: 6

Compression:

Stored size: 582 Bytes

Contents

require "erb"
require "yaml"

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

    def load_file(path, environment)
      # First, load the ERB template from disk.
      template = ERB.new(File.new(path).read)

      # The last argument to `safe_load` allows us to use aliasing to share
      # configuration between environments.
      processed = YAML.safe_load(template.result(binding), [], [], true)

      processed.fetch(environment).each do |variable, value|
        @config.set(variable, value)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
king_konf-0.1.5 lib/king_konf/config_file_loader.rb
king_konf-0.1.4 lib/king_konf/config_file_loader.rb
king_konf-0.1.3 lib/king_konf/config_file_loader.rb
king_konf-0.1.2 lib/king_konf/config_file_loader.rb
king_konf-0.1.1 lib/king_konf/config_file_loader.rb
king_konf-0.1.0 lib/king_konf/config_file_loader.rb