Sha256: 3f1b3ee18cf8e73af78b41de6be9fdd27f83ffca38ab389db0c8f66f04ceba06

Contents?: true

Size: 688 Bytes

Versions: 1

Compression:

Stored size: 688 Bytes

Contents

require "yaml"
require "erb"

module Econfig
  class YAML
    def initialize(path)
      @path = path
      @mutex = Mutex.new
      @options = nil
    end

    def get(key)
      options[key]
    end

    def has_key?(key)
      options.has_key?(key)
    end

  private

    def path
      raise Econfig::UninitializedError, "Econfig.root is not set" unless Econfig.root
      File.expand_path(@path, Econfig.root)
    end

    def options
      return @options if @options

      @mutex.synchronize do
        @options ||= if File.exist?(path)
          ::YAML.load(::ERB.new(File.read(path)).result)[Econfig.env] || {}
        else
          {}
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
econfig-2.0.0 lib/econfig/yaml.rb