diff options
author | Michael Bleigh <michael@intridea.com> | 2010-08-19 18:25:03 -0500 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-08-19 18:25:03 -0500 |
commit | f670fb3a7bbfb971b06cdc415e76b091667f933d (patch) | |
tree | 5e42f6d83c41c1d5c6e0732937d70322e9c80e44 | |
parent | f299f6363784f1e831d827a284c8d7d6b35dbeec (diff) | |
download | hashie-f670fb3a7bbfb971b06cdc415e76b091667f933d.tar.gz |
Do not convert child mashes, retain their class.
-rw-r--r-- | lib/hashie.rb | 12 | ||||
-rw-r--r-- | lib/hashie/hash_extensions.rb | 2 | ||||
-rw-r--r-- | lib/hashie/mash.rb | 4 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 10 | ||||
-rw-r--r-- | spec/spec.opts | 3 |
5 files changed, 22 insertions, 9 deletions
diff --git a/lib/hashie.rb b/lib/hashie.rb index 0a1e9ba..02478a0 100644 --- a/lib/hashie.rb +++ b/lib/hashie.rb @@ -1,9 +1,9 @@ -require 'hashie/hash_extensions' -require 'hashie/hash' -require 'hashie/mash' -require 'hashie/dash' -require 'hashie/clash' - module Hashie + autoload :HashExtensions, 'hashie/hash_extensions' + autoload :PrettyInspect, 'hashie/hash_extensions' + autoload :Hash, 'hashie/hash' autoload :Trash, 'hashie/trash' + autoload :Mash, 'hashie/mash' + autoload :Dash, 'hashie/dash' + autoload :Clash, 'hashie/clash' end diff --git a/lib/hashie/hash_extensions.rb b/lib/hashie/hash_extensions.rb index 956ec99..174c280 100644 --- a/lib/hashie/hash_extensions.rb +++ b/lib/hashie/hash_extensions.rb @@ -27,7 +27,7 @@ module Hashie # Convert this hash into a Mash def to_mash - Hashie::Mash.new(self) + ::Hashie::Mash.new(self) end end diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index bcc976b..218c341 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -86,7 +86,7 @@ module Hashie alias_method :regular_dup, :dup # Duplicates the current mash as a new mash. def dup - Mash.new(self, self.default) + self.class.new(self, self.default) end def key?(key) @@ -141,6 +141,8 @@ module Hashie def convert_value(val, duping=false) #:nodoc: case val + when ::Hashie::Mash + val.dup when ::Hash val = val.dup if duping self.class.new(val) diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index c927a87..fd1af79 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -90,6 +90,16 @@ describe Hashie::Mash do record.son.class.should == MyMash end + it "should not change the class of Mashes when converted" do + class SubMash < Hashie::Mash + end + + record = Hashie::Mash.new + son = SubMash.new + record['submash'] = son + record['submash'].should be_kind_of(SubMash) + end + describe '#respond_to?' do it 'should respond to a normal method' do Hashie::Mash.new.should be_respond_to(:key?) diff --git a/spec/spec.opts b/spec/spec.opts index 44f9a9c..3acf0e7 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,2 +1,3 @@ --colour ---format progress
\ No newline at end of file +--format progress +--backtrace
\ No newline at end of file |