require "hashie/mash"
require "erb"
require "yaml"

require "dsc/version"
require "dsc/mash"

module Dsc
  UndefinedAttribute = Class.new(NoMethodError)

  def self.load_file(file_path, env: "development", optional: [])
    optional_hash = optional.map { |key| [key, nil] }.to_h
    config_yaml = ERB.new(File.read(file_path)).result
    config_hash = optional_hash.merge(YAML::load(config_yaml)[env])

    Dsc::Mash.new(config_hash)
  end
end