diff options
-rw-r--r-- | lib/psych.rb | 1 | ||||
-rw-r--r-- | lib/psych/deprecated.rb | 18 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 24 | ||||
-rw-r--r-- | test/psych/test_exception.rb | 13 | ||||
-rw-r--r-- | test/psych/test_to_yaml_properties.rb | 64 |
5 files changed, 2 insertions, 118 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index b117b25..9959320 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -17,7 +17,6 @@ require 'psych/omap' require 'psych/set' require 'psych/coder' require 'psych/core_ext' -require 'psych/deprecated' require 'psych/stream' require 'psych/json/tree_builder' require 'psych/json/stream' diff --git a/lib/psych/deprecated.rb b/lib/psych/deprecated.rb deleted file mode 100644 index 8046ba4..0000000 --- a/lib/psych/deprecated.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: false -require 'date' - -module Psych - DEPRECATED = __FILE__ # :nodoc: - - module DeprecatedMethods # :nodoc: - attr_accessor :taguri - attr_accessor :to_yaml_style - end -end - -class Object - undef :to_yaml_properties rescue nil - def to_yaml_properties # :nodoc: - instance_variables - end -end diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 55edbc0..978af00 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -336,7 +336,7 @@ module Psych end is_primitive = o.class == ::String - ivars = find_ivars o, is_primitive + ivars = is_primitive ? [] : o.instance_variables if ivars.empty? unless is_primitive @@ -527,24 +527,6 @@ module Psych end end - # FIXME: remove this method once "to_yaml_properties" is removed - def find_ivars target, is_primitive=false - begin - loc = target.method(:to_yaml_properties).source_location.first - unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb') - if $VERBOSE - warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" - end - return target.to_yaml_properties - end - rescue - # public_method or source_location might be overridden, - # and it's OK to skip it since it's only to emit a warning. - end - - is_primitive ? [] : target.instance_variables - end - def register target, yaml_obj @st.register target, yaml_obj yaml_obj @@ -586,9 +568,7 @@ module Psych end def dump_ivars target - ivars = find_ivars target - - ivars.each do |iv| + target.instance_variables.each do |iv| @emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY) accept target.instance_variable_get(iv) end diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index 85fa78f..fa80fdb 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -121,19 +121,6 @@ module Psych assert_equal 2, w.bar end - def test_to_yaml_properties - class << @wups - def to_yaml_properties - [:@foo] - end - end - - w = Psych.load(Psych.dump(@wups)) - assert_equal @wups, w - assert_equal 1, w.foo - assert_nil w.bar - end - def test_psych_syntax_error Tempfile.create(['parsefile', 'yml']) do |t| t.binmode diff --git a/test/psych/test_to_yaml_properties.rb b/test/psych/test_to_yaml_properties.rb deleted file mode 100644 index 8a29b6a..0000000 --- a/test/psych/test_to_yaml_properties.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: false -require_relative 'helper' - -module Psych - class TestToYamlProperties < Psych::TestCase - class Foo - attr_accessor :a, :b, :c - def initialize - @a = 1 - @b = 2 - @c = 3 - end - - def to_yaml_properties - [:@a, :@b] - end - end - - def test_object_dump_yaml_properties - foo = Psych.load(Psych.dump(Foo.new)) - assert_equal 1, foo.a - assert_equal 2, foo.b - assert_nil foo.c - end - - class Bar < Struct.new(:foo, :bar) - attr_reader :baz - def initialize *args - super - @baz = 'hello' - end - - def to_yaml_properties - [] - end - end - - def test_struct_dump_yaml_properties - bar = Psych.load(Psych.dump(Bar.new('a', 'b'))) - assert_equal 'a', bar.foo - assert_equal 'b', bar.bar - assert_nil bar.baz - end - - def test_string_dump - string = "okonomiyaki" - class << string - def to_yaml_properties - [:@tastes] - end - end - - string.instance_variable_set(:@tastes, 'delicious') - v = Psych.load Psych.dump string - assert_equal 'delicious', v.instance_variable_get(:@tastes) - end - - def test_string_load_syck - str = Psych.load("--- !str \nstr: okonomiyaki\n:@tastes: delicious\n") - assert_equal 'okonomiyaki', str - assert_equal 'delicious', str.instance_variable_get(:@tastes) - end - end -end |