Sha256: 4a2abd6803c5d17318842119b6f2fa86865c21e97393842c5cab8840d8abf545

Contents?: true

Size: 653 Bytes

Versions: 15

Compression:

Stored size: 653 Bytes

Contents

require 'yaml'
require 'erb'

module Config
  module Sources
    class YAMLSource
      attr_accessor :path

      def initialize(path)
        @path = path
      end

      # returns a config hash from the YML file
      def load
        if @path and File.exist?(@path.to_s)
          result = YAML.load(ERB.new(IO.read(@path.to_s)).result)
        end
        result || {}
      rescue Psych::SyntaxError => e
        raise "YAML syntax error occurred while parsing #{@path}. " \
              "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
              "Error: #{e.message}"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
config-1.7.0 lib/config/sources/yaml_source.rb
config-1.6.1 lib/config/sources/yaml_source.rb
config-1.6.0 lib/config/sources/yaml_source.rb
config-1.5.1 lib/config/sources/yaml_source.rb
config-1.5.0 lib/config/sources/yaml_source.rb
config-1.4.0 lib/config/sources/yaml_source.rb
config-1.3.0 lib/config/sources/yaml_source.rb
config-1.2.1 lib/config/sources/yaml_source.rb
config-1.2.0 lib/config/sources/yaml_source.rb
config-1.1.1 lib/config/sources/yaml_source.rb
config-1.1.0 lib/config/sources/yaml_source.rb
config-1.0.0 lib/config/sources/yaml_source.rb
config-1.0.0.beta3 lib/config/sources/yaml_source.rb
config-1.0.0.beta2 lib/config/sources/yaml_source.rb
config-1.0.0.beta1 lib/config/sources/yaml_source.rb