Sha256: 36418dba82f8dd8ce328b22f8c670ceb561817d19d6cfbaaed1f4d213b56960b

Contents?: true

Size: 731 Bytes

Versions: 1

Compression:

Stored size: 731 Bytes

Contents

require 'yaml'

class Isomer::Sources::Yaml < Isomer::Sources::Base
  attr_reader :file, :base, :required

  def initialize(parameters, options={})
    @file = options[:file].to_s
    raise Isomer::Error, "YAML source requires the 'file' parameter" if file.empty?

    @base = options[:base]
    @required = !!options[:required]

    super(parameters)
  end

  def load
    if File.exists?(file)
      values = YAML.load_file(file)
      if base && values.has_key?(base)
        @configuration = values[base]
      else
        @configuration = values
      end

      @configuration ||= {}
    else
      raise Isomer::Error, "Missing required configuration file '#{file}'" if required
      @configuration = {}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
isomer-0.1.2 lib/isomer/sources/yaml.rb