lib/confrider/core.rb in confrider-0.1.0 vs lib/confrider/core.rb in confrider-0.2.0

- old
+ new

@@ -1,38 +1,40 @@ -class Confrider::Core - def initialize - @vault = {} - end +module Confrider + class Core + def initialize + @vault = Confrider::Vault.new + end - def [](key, default_value = nil) - @vault.fetch(key, default_value) - end + def [](key, default_value = nil) + @vault.fetch(key, default_value) + end - def from_hash(hash) - save_hash(nil, hash) - end + def from_hash(hash) + save_hash(nil, hash) + end - def normalize_keys(*keys) - keys.join('.').gsub(/^\./, '') - end + def normalize_keys(*keys) + keys.join('.').gsub(/^\./, '') + end - private + private - def save(key, value) - @vault[key] = value - end - - def save_hash(key, hash) - if key - @vault[key] ||= {} - @vault[key].deep_merge!(hash) + def save(key, value) + @vault[key] = value 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) + + 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