summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-05 13:16:32 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-05 13:16:32 +0000
commit6d77e28763ed17f75edf3b4072701b4dbd7644bb (patch)
treee56f68d61222a1cf4bfc6a63aa640c6546a41b91 /ext/psych/lib/psych
parent4389ba641f89fe9d4e5c575442968d385c4183e8 (diff)
Import psych-3.0.0.beta1 from ruby/psych.
* Removed deprecated code. * Removed code related syck gem. * Fixed typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych')
-rw-r--r--ext/psych/lib/psych/core_ext.rb19
-rw-r--r--ext/psych/lib/psych/deprecated.rb86
-rw-r--r--ext/psych/lib/psych/scalar_scanner.rb5
-rw-r--r--ext/psych/lib/psych/versions.rb2
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb5
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb51
6 files changed, 6 insertions, 162 deletions
diff --git a/ext/psych/lib/psych/core_ext.rb b/ext/psych/lib/psych/core_ext.rb
index 1a98279..1232abf 100644
--- a/ext/psych/lib/psych/core_ext.rb
+++ b/ext/psych/lib/psych/core_ext.rb
@@ -4,31 +4,14 @@ class Object
Psych.add_tag(url, self)
end
- # FIXME: rename this to "to_yaml" when syck is removed
-
###
# call-seq: to_yaml(options = {})
#
# Convert an object to YAML. See Psych.dump for more information on the
# available +options+.
- def psych_to_yaml options = {}
+ def to_yaml options = {}
Psych.dump self, options
end
- remove_method :to_yaml rescue nil
- alias :to_yaml :psych_to_yaml
-end
-
-class Module
- def psych_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
-
- remove_method :yaml_as rescue nil
- alias :yaml_as :psych_yaml_as
end
if defined?(::IRB)
diff --git a/ext/psych/lib/psych/deprecated.rb b/ext/psych/lib/psych/deprecated.rb
deleted file mode 100644
index 165d210..0000000
--- a/ext/psych/lib/psych/deprecated.rb
+++ /dev/null
@@ -1,86 +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
-
- def self.quick_emit thing, opts = {}, &block # :nodoc:
- warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
- target = eval 'self', block.binding
- target.extend DeprecatedMethods
- metaclass = class << target; self; end
- metaclass.send(:define_method, :encode_with) do |coder|
- target.taguri = coder.tag
- target.to_yaml_style = coder.style
- block.call coder
- end
- target.psych_to_yaml unless opts[:nodump]
- 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/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb
index a849359..449efa4 100644
--- a/ext/psych/lib/psych/scalar_scanner.rb
+++ b/ext/psych/lib/psych/scalar_scanner.rb
@@ -10,7 +10,6 @@ module Psych
# Taken from http://yaml.org/type/float.html
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
- |[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60)
|[-+]?\.(inf|Inf|INF)(?# infinity)
|\.(nan|NaN|NAN)(?# not a number))$/x
@@ -83,13 +82,13 @@ module Psych
else
@symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
end
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
+ when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/
i = 0
string.split(':').each_with_index do |n,e|
i += (n.to_i * 60 ** (e - 2).abs)
end
i
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/
+ when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/
i = 0
string.split(':').each_with_index do |n,e|
i += (n.to_f * 60 ** (e - 2).abs)
diff --git a/ext/psych/lib/psych/versions.rb b/ext/psych/lib/psych/versions.rb
index 689d4f3..12029f0 100644
--- a/ext/psych/lib/psych/versions.rb
+++ b/ext/psych/lib/psych/versions.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
module Psych
# The version is Psych you're using
- VERSION = '2.2.3'
+ VERSION = '3.0.0.beta1'
if RUBY_ENGINE == 'jruby'
DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index fd1c8e6..d1318b3 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/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/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 11214ec..cae876c 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/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 !~ /(syck\/rubytypes.rb|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