diff options
author | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2017-04-05 20:33:52 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-05 20:33:52 +0900 |
commit | 130b17ee48a443d8c0aa35fde451082bb968b998 (patch) | |
tree | f1b75eb078ec8c05443b327b97ef2d3d1fc1f573 | |
parent | d4bd8967c1d9fe15c0ab71d03fd63459884b68b7 (diff) | |
parent | 712a65a53f3c15105cd86e8ad3ee3c779050ada4 (diff) | |
download | psych-130b17ee48a443d8c0aa35fde451082bb968b998.tar.gz |
Merge pull request #312 from ruby/remove-deprecated-methods
Remove deprecated methods
-rw-r--r-- | lib/psych.rb | 1 | ||||
-rw-r--r-- | lib/psych/core_ext.rb | 10 | ||||
-rw-r--r-- | lib/psych/deprecated.rb | 73 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 5 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 51 | ||||
-rw-r--r-- | psych.gemspec | 2 | ||||
-rw-r--r-- | test/psych/test_deprecated.rb | 89 | ||||
-rw-r--r-- | test/psych/test_exception.rb | 13 | ||||
-rw-r--r-- | test/psych/test_psych.rb | 4 | ||||
-rw-r--r-- | test/psych/test_to_yaml_properties.rb | 64 | ||||
-rw-r--r-- | test/psych/test_yaml.rb | 4 |
11 files changed, 7 insertions, 309 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/core_ext.rb b/lib/psych/core_ext.rb index 4bfd7bd..1232abf 100644 --- a/lib/psych/core_ext.rb +++ b/lib/psych/core_ext.rb @@ -14,16 +14,6 @@ class Object end end -class Module - def yaml_as url - return if caller[0].end_with?('rubytypes.rb') - if $VERBOSE - warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag" - end - Psych.add_tag(url, self) - end -end - if defined?(::IRB) require 'psych/y' end diff --git a/lib/psych/deprecated.rb b/lib/psych/deprecated.rb deleted file mode 100644 index 6a98eec..0000000 --- a/lib/psych/deprecated.rb +++ /dev/null @@ -1,73 +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 - - # This method is deprecated, use Psych.load_stream instead. - def self.load_documents yaml, &block - if $VERBOSE - warn "#{caller[0]}: load_documents is deprecated, use load_stream" - end - list = load_stream yaml - return list unless block_given? - list.each(&block) - end - - def self.detect_implicit thing - warn "#{caller[0]}: detect_implicit is deprecated" if $VERBOSE - return '' unless String === thing - return 'null' if '' == thing - ss = ScalarScanner.new(ClassLoader.new) - ss.tokenize(thing).class.name.downcase - end - - def self.add_ruby_type type_tag, &block - warn "#{caller[0]}: add_ruby_type is deprecated, use add_domain_type" if $VERBOSE - domain = 'ruby.yaml.org,2002' - key = ['tag', domain, type_tag].join ':' - @domain_types[key] = [key, block] - end - - def self.add_private_type type_tag, &block - warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE - domain = 'x-private' - key = [domain, type_tag].join ':' - @domain_types[key] = [key, block] - end - - def self.tagurize thing - warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE - 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 - undef :to_yaml_properties rescue nil - def to_yaml_properties # :nodoc: - instance_variables - end -end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index fd1c8e6..d1318b3 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -380,11 +380,6 @@ module Psych if o.respond_to?(:init_with) o.init_with c - elsif o.respond_to?(:yaml_initialize) - if $VERBOSE - warn "Implementing #{o.class}#yaml_initialize is deprecated, please implement \"init_with(coder)\"" - end - o.yaml_initialize c.tag, c.map else h.each { |k,v| o.instance_variable_set(:"@#{k}", v) } end diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 55edbc0..cae876c 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -53,15 +53,6 @@ module Psych new(emitter, ss, options) end - def self.new emitter = nil, ss = nil, options = nil - return super if emitter && ss && options - - if $VERBOSE - warn "This API is deprecated, please pass an emitter, scalar scanner, and options or call #{self}.create() (#{caller.first})" - end - create emitter, ss - end - def initialize emitter, ss, options super() @started = false @@ -139,24 +130,6 @@ module Psych return @emitter.alias anchor end - if target.respond_to?(:to_yaml) - begin - loc = target.method(:to_yaml).source_location.first - if loc !~ /psych\/core_ext.rb/ - unless target.respond_to?(:encode_with) - if $VERBOSE - warn "implementing to_yaml is deprecated, please implement \"encode_with\"" - end - - target.to_yaml(:nodump => true) - end - 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 - end - if target.respond_to?(:encode_with) dump_coder target else @@ -336,7 +309,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 +500,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 +541,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/psych.gemspec b/psych.gemspec index 53a28fe..73e3c34 100644 --- a/psych.gemspec +++ b/psych.gemspec @@ -17,7 +17,7 @@ DESCRIPTION s.require_paths = ["lib"] # for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - s.files = [".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console", "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/deprecated.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", "lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb", "lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb", "lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb", "lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb", "lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb", "lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb", "lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"] + s.files = [".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console", "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", "lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb", "lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb", "lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb", "lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb", "lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb", "lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb", "lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"] s.rdoc_options = ["--main", "README.md"] s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"] diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index c2db0c5..eab2302 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -49,30 +49,6 @@ module Psych assert_nil qe.value end - class YamlInit - attr_reader :name - attr_reader :value - - def initialize - @name = 'hello!!' - @value = 'Friday!' - end - - def yaml_initialize tag, vals - vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' } - end - end - - def test_yaml_initialize - hash = { :yi => YamlInit.new } - hash2 = Psych.load Psych.dump hash - yi = hash2[:yi] - - assert_equal 'TGIF!', yi.name - assert_equal 'TGIF!', yi.value - assert_instance_of YamlInit, yi - end - class YamlInitAndInitWith attr_reader :name attr_reader :value @@ -111,70 +87,5 @@ module Psych assert_equal 'some string', coder.scalar assert_equal :scalar, coder.type end - - class YamlAs - TestCase.suppress_warning do - yaml_as 'helloworld' - end - end - - def test_yaml_as - assert_match(/helloworld/, Psych.dump(YamlAs.new)) - end - - def test_ruby_type - types = [] - appender = lambda { |*args| types << args } - - Psych.add_ruby_type('foo', &appender) - Psych.load <<-eoyml -- !ruby.yaml.org,2002/foo bar - eoyml - - assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types - end - - def test_detect_implicit - assert_equal '', Psych.detect_implicit(nil) - assert_equal '', Psych.detect_implicit(Object.new) - assert_equal '', Psych.detect_implicit(1.2) - assert_equal 'null', Psych.detect_implicit('') - assert_equal 'string', Psych.detect_implicit('foo') - end - - def test_private_type - types = [] - Psych.add_private_type('foo') { |*args| types << args } - Psych.load <<-eoyml -- !x-private:foo bar - eoyml - - assert_equal [["x-private:foo", "bar"]], types - end - - def test_tagurize - assert_nil Psych.tagurize nil - 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/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_psych.rb b/test/psych/test_psych.rb index 0e76927..24030d5 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -98,8 +98,8 @@ class TestPsych < Psych::TestCase assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION end - def test_load_documents - docs = Psych.load_documents("--- foo\n...\n--- bar\n...") + def test_load_stream + docs = Psych.load_stream("--- foo\n...\n--- bar\n...") assert_equal %w{ foo bar }, docs end 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 diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index f8e9e2f..cfba770 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -512,7 +512,7 @@ EOY def test_spec_log_file doc_ct = 0 - Psych::load_documents( <<EOY + Psych::load_stream( <<EOY --- Time: 2001-11-23 15:01:42 -05:00 User: ed @@ -585,7 +585,7 @@ EOY def test_spec_oneline_docs doc_ct = 0 - Psych::load_documents( <<EOY + Psych::load_stream( <<EOY # The following is a sequence of three documents. # The first contains an empty mapping, the second # an empty sequence, and the last an empty string. |