Sha256: 6bd88ae31c3d560b0d538b46118d172f9e68896aef82e6a0fcb7b81c0f88d66d

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

require "erb"
require "forwardable"
require_relative "value_parser"

module Eye::Patch

  class Settings
    extend Forwardable
    def_delegators :parsed, :[], :fetch

    def initialize(filename)
      file = File.new(filename)
      erb = ERB.new(file.read)
      erb.filename = file.path

      @settings = YAML.load(erb.result)
    end

    private

    def parsed
      @parsed ||= parse(@settings)
    end

    def parse(item)
      case item
      when Hash
        item.each_with_object({}) do |(key, val), result|
          result[key.to_sym] = parse(val)
        end
      when Array
        item.map { |val| parse(val) }
      when String
        ValueParser.parse(item)
      else
        item
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eye-patch-0.3.1 lib/eye/patch/settings.rb