Permalink
Browse files

Issue #14: #configure loses nested hashes somehow

  • Loading branch information...
1 parent 875485e commit 6a9975ba87e96d90ac746840a3a11152ae8c9543 @mbklein committed Sep 18, 2012
View
4 lib/confstruct/configuration.rb
@@ -6,7 +6,7 @@ class Configuration < HashWithStructAccess
def initialize hash=@@hash_class.new, &block
super({})
- @default_values = hash.is_a?(HashWithStructAccess) ? hash : HashWithStructAccess.from_hash(hash)
+ @default_values = HashWithStructAccess.from_hash(hash)
eval_or_yield @default_values, &block
reset_defaults!
end
@@ -16,7 +16,7 @@ def after_config! obj
def configure *args, &block
if args[0].respond_to?(:each_pair)
- self.deep_merge!(args[0])
+ self.deep_merge!(HashWithStructAccess.from_hash(args[0]))
end
eval_or_yield self, &block
after_config! self
View
1 lib/confstruct/hash_with_struct_access.rb
@@ -46,6 +46,7 @@ class HashWithStructAccess
class << self
def from_hash hash
+ return hash if hash.is_a?(self)
symbolized_hash = symbolize_hash hash
self.new(symbolized_hash)
end
View
6 spec/confstruct/configuration_spec.rb
@@ -127,6 +127,12 @@ def @config.after_config! obj
mock postconfigurator
end
end
+
+ it "should be initializable with a string-keyed hash" do
+ conf = Confstruct::Configuration.new
+ conf.configure(:top=>{:middle=>{"one"=>"two"}})
+ conf.top.middle.one.should == 'two'
+ end
end
end

0 comments on commit 6a9975b

Please sign in to comment.