Sha256: 8a9deca527d4e4650d610b22b39f434d6a54a36b0995b86409d26424cfcc8b41

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

module Confrider
  class Core
    def initialize
      @vault = Confrider::Vault.new
    end

    def [](key, default_value = nil)
      @vault.fetch(key, default_value)
    end

    def from_hash(hash)
      save_hash(nil, hash)
    end

    def normalize_keys(*keys)
      keys.join('.').gsub(/^\./, '')
    end

    private

    def save(key, value)
      @vault[key] = value
    end

    def save_hash(key, hash)
      if key
        @vault[key] ||= Confrider::Vault.new
        @vault[key].deep_merge!(hash)
      end
      hash.each do |inner_key, value|
        normalized_key = normalize_keys(key, inner_key)
        if value.is_a? Hash
          save_hash(normalized_key, value)
        else
          save(normalized_key, value)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
confrider-0.2.0 lib/confrider/core.rb