Sha256: 867bf838a161ddddf0c6f90f7a6008cae5ca54a1ed2a95c3b51bebe48c3d7315

Contents?: true

Size: 665 Bytes

Versions: 8

Compression:

Stored size: 665 Bytes

Contents

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

module Eye::Patch

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

    def initialize(filename)
      @settings = YAML.load(ERB.new(File.read(filename)).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

8 entries across 8 versions & 1 rubygems

Version Path
eye-patch-0.3.0 lib/eye/patch/settings.rb
eye-patch-0.2.2 lib/eye/patch/settings.rb
eye-patch-0.2.1 lib/eye/patch/settings.rb
eye-patch-0.2.0 lib/eye/patch/settings.rb
eye-patch-0.1.8 lib/eye/patch/settings.rb
eye-patch-0.1.7 lib/eye/patch/settings.rb
eye-patch-0.1.6 lib/eye/patch/settings.rb
eye-patch-0.1.5 lib/eye/patch/settings.rb