diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-05-03 08:17:12 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-05-03 08:17:12 -0700 |
commit | 17b2deaa6e487e565d43c526a50d9974a54f5bbd (patch) | |
tree | 66e89731f4f0b70856adcb1d4abc7dbd9a14ae6f | |
parent | 88bcb83729ebea6a7d4581b3100dfa7a783a9ff7 (diff) | |
download | psych-17b2deaa6e487e565d43c526a50d9974a54f5bbd.zip |
merging from ruby
-rw-r--r-- | lib/psych/deprecated.rb | 17 | ||||
-rw-r--r-- | test/psych/test_deprecated.rb | 19 | ||||
-rw-r--r-- | test/psych/visitors/test_yaml_tree.rb | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/lib/psych/deprecated.rb b/lib/psych/deprecated.rb index 1d401d9..f4034e3 100644 --- a/lib/psych/deprecated.rb +++ b/lib/psych/deprecated.rb @@ -56,6 +56,23 @@ module Psych return thing unless String === thing "tag:yaml.org,2002:#{thing}" end + + def self.read_type_class type, reference + warn "#{caller[0]}: read_type_class is deprecated" if $VERBOSE + _, _, type, name = type.split ':', 4 + + reference = name.split('::').inject(reference) do |k,n| + k.const_get(n.to_sym) + end if name + [type, reference] + end + + def self.object_maker klass, hash + warn "#{caller[0]}: object_maker is deprecated" if $VERBOSE + klass.allocate.tap do |obj| + hash.each { |k,v| obj.instance_variable_set(:"@#{k}", v) } + end + end end class Object diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index 6db7238..a272db2 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -187,5 +187,24 @@ module Psych assert_equal Psych, Psych.tagurize(Psych) assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo') end + + def test_read_type_class + things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object + assert_equal 'int', things.first + assert_equal Psych::TestDeprecated::QuickEmitter, things.last + end + + def test_read_type_class_no_class + things = Psych.read_type_class 'tag:yaml.org,2002:int', Object + assert_equal 'int', things.first + assert_equal Object, things.last + end + + def test_object_maker + thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' }) + assert_instance_of(Object, thing) + assert_equal 'b', thing.instance_variable_get(:@a) + assert_equal 'd', thing.instance_variable_get(:@c) + end end end diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index 292710b..758cfae 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -23,6 +23,7 @@ module Psych def test_struct_const foo = Struct.new("Foo", :bar) assert_cycle foo.new('bar') + Struct.instance_eval { remove_const(:Foo) } end A = Struct.new(:foo) |