diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-04-16 20:00:31 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-04-16 20:00:31 -0700 |
commit | 0097c811dcd31038ec63de366d30b83061656fdc (patch) | |
tree | 43019fc39ec8b043e8ea7840be55b50e1d5a3baf /lib | |
parent | 2197a9e30126df626771d4360607dba8fa92e533 (diff) | |
download | psych-0097c811dcd31038ec63de366d30b83061656fdc.zip |
merging from ruby
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/coder.rb | 11 | ||||
-rw-r--r-- | lib/psych/core_ext.rb | 13 | ||||
-rw-r--r-- | lib/psych/deprecated.rb | 10 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 21 |
4 files changed, 48 insertions, 7 deletions
diff --git a/lib/psych/coder.rb b/lib/psych/coder.rb index eff0cc3..c06c9c1 100644 --- a/lib/psych/coder.rb +++ b/lib/psych/coder.rb @@ -7,7 +7,7 @@ module Psych # called, respectively. class Coder attr_accessor :tag, :style, :implicit - attr_reader :type, :scalar, :seq + attr_reader :type, :seq def initialize tag @map = {} @@ -19,6 +19,15 @@ module Psych @scalar = nil end + def scalar *args + if args.length > 0 + warn "#{caller[0]}: Coder#scalar(a,b,c) is deprecated" if $VERBOSE + @tag, @scalar, _ = args + @type = :scalar + end + @scalar + end + # Emit a map. The coder will be yielded to the block. def map tag = @tag, style = @style @tag = tag diff --git a/lib/psych/core_ext.rb b/lib/psych/core_ext.rb index 9c55c70..8d3e8fb 100644 --- a/lib/psych/core_ext.rb +++ b/lib/psych/core_ext.rb @@ -16,6 +16,19 @@ class Object 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 + module Kernel def psych_y *objects puts Psych.dump_stream(*objects) diff --git a/lib/psych/deprecated.rb b/lib/psych/deprecated.rb index 5a96e91..26e431d 100644 --- a/lib/psych/deprecated.rb +++ b/lib/psych/deprecated.rb @@ -1,4 +1,8 @@ +require 'date' + module Psych + DEPRECATED = __FILE__ # :nodoc: + module DeprecatedMethods # :nodoc: attr_accessor :taguri attr_accessor :to_yaml_style @@ -17,3 +21,9 @@ module Psych target.psych_to_yaml unless opts[:nodump] end end + +class Object + 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 3cbb695..4f990a7 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -182,9 +182,7 @@ module Psych plain = !quote end - ivars = o.respond_to?(:to_yaml_properties) ? - o.to_yaml_properties : - o.instance_variables + ivars = find_ivars o scalar = create_scalar str, nil, tag, plain, quote @@ -251,6 +249,19 @@ module Psych end private + # FIXME: remove this method once "to_yaml_properties" is removed + def find_ivars target + m = target.method(:to_yaml_properties) + unless m.source_location.first.start_with?(Psych::DEPRECATED) + if $VERBOSE + warn "to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" + end + return target.to_yaml_properties + end + + target.instance_variables + end + def append o @stack.last.children << o o @@ -295,9 +306,7 @@ module Psych end def dump_ivars target, map - ivars = target.respond_to?(:to_yaml_properties) ? - target.to_yaml_properties : - target.instance_variables + ivars = find_ivars target ivars.each do |iv| map.children << create_scalar("#{iv.to_s.sub(/^@/, '')}") |