summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-19 11:45:39 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-19 11:45:39 +0000
commit09f5560c5721ad779cc2e740c4a77ad6aca1b530 (patch)
tree5d8d6ada2d2bed32c7d8f39dc616d9c26dbfac51 /lib
parent8e3bfe98614414f027eed4e33b80dab0e938d13b (diff)
Merge everything from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/yaml.rb4
-rw-r--r--lib/yaml/baseemitter.rb2
-rw-r--r--lib/yaml/encoding.rb6
-rw-r--r--lib/yaml/rubytypes.rb18
-rw-r--r--lib/yaml/store.rb20
-rw-r--r--lib/yaml/tag.rb7
-rw-r--r--lib/yaml/types.rb6
7 files changed, 41 insertions, 22 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb
index fe8335c8f0..a8da42a321 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -384,6 +384,10 @@ module YAML
else
emitter.reset( opts )
end
+ oid =
+ case oid when Fixnum, NilClass; oid
+ else oid = "#{oid.object_id}-#{oid.hash}"
+ end
out.emit( oid, &e )
end
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb
index 1aef152749..a1992f498b 100644
--- a/lib/yaml/baseemitter.rb
+++ b/lib/yaml/baseemitter.rb
@@ -132,7 +132,7 @@ module YAML
# Folding paragraphs within a column
#
def fold( value )
- value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
+ value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do
$1 || $2 + ( $3 || "\n" )
end
end
diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb
index 37f5cfda64..57dc553606 100644
--- a/lib/yaml/encoding.rb
+++ b/lib/yaml/encoding.rb
@@ -10,8 +10,8 @@ module YAML
def YAML.escape( value, skip = "" )
value.gsub( /\\/, "\\\\\\" ).
gsub( /"/, "\\\"" ).
- gsub( /([\x00-\x1f])/ ) do |x|
- skip[x] || ESCAPES[ x.unpack("C")[0] ]
+ gsub( /([\x00-\x1f])/ ) do
+ skip[$&] || ESCAPES[ $&.unpack("C")[0] ]
end
end
@@ -19,7 +19,7 @@ module YAML
# Unescape the condenses escapes
#
def YAML.unescape( value )
- value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x|
+ value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
if $3
["#$3".hex ].pack('U*')
elsif $2
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index c71b704b43..35b719196e 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -12,7 +12,7 @@ class Object
def to_yaml_style; end
def to_yaml_properties; instance_variables.sort; end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
to_yaml_properties.each do |m|
map.add( m[1..-1], instance_variable_get( m ) )
@@ -35,7 +35,7 @@ class Hash
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
each do |k, v|
map.add( k, v )
@@ -83,7 +83,7 @@ class Struct
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
#
# Basic struct is passed as a YAML map
#
@@ -104,7 +104,7 @@ class Array
yaml_as "tag:yaml.org,2002:seq"
def yaml_initialize( tag, val ); concat( val.to_a ); end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
each do |x|
seq.add( x )
@@ -124,7 +124,7 @@ class Exception
o
end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
map.add( 'message', message )
to_yaml_properties.each do |m|
@@ -161,7 +161,7 @@ class String
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
+ YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
elsif to_yaml_properties.empty?
@@ -227,7 +227,7 @@ class Range
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
# not to_yaml_properties.empty?
@@ -310,7 +310,7 @@ class Time
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
tz = "Z"
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
unless self.utc?
@@ -347,7 +347,7 @@ end
class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
end
end
diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb
index 2ffa9554b9..e3a8e9fcdd 100644
--- a/lib/yaml/store.rb
+++ b/lib/yaml/store.rb
@@ -20,10 +20,24 @@ class YAML::Store < PStore
end
def load(content)
- YAML::load(content)
+ table = YAML::load(content)
+ if table == false
+ {}
+ else
+ table
+ end
+ end
+
+ def marshal_dump_supports_canonical_option?
+ false
end
- def load_file(file)
- YAML::load(file)
+ EMPTY_MARSHAL_DATA = {}.to_yaml
+ EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
+ def empty_marshal_data
+ EMPTY_MARSHAL_DATA
+ end
+ def empty_marshal_checksum
+ EMPTY_MARSHAL_CHECKSUM
end
end
diff --git a/lib/yaml/tag.rb b/lib/yaml/tag.rb
index 56c3513bc0..0fb6bef9a0 100644
--- a/lib/yaml/tag.rb
+++ b/lib/yaml/tag.rb
@@ -51,11 +51,12 @@ module YAML
end
class Module
+ # :stopdoc:
# Adds a taguri _tag_ to a class, used when dumping or loading the class
# in YAML. See YAML::tag_class for detailed information on typing and
# taguris.
- def yaml_as( tag, sc = true ) # :nodoc:
+ def yaml_as( tag, sc = true )
verbose, $VERBOSE = $VERBOSE, nil
class_eval <<-"end;", __FILE__, __LINE__+1
attr_writer :taguri
@@ -79,12 +80,12 @@ class Module
end
# Transforms the subclass name into a name suitable for display
# in a subclassed tag.
- def yaml_tag_class_name # :nodoc:
+ def yaml_tag_class_name
self.name
end
# Transforms the subclass name found in the tag into a Ruby
# constant name.
- def yaml_tag_read_class( name ) # :nodoc:
+ def yaml_tag_read_class( name )
name
end
end
diff --git a/lib/yaml/types.rb b/lib/yaml/types.rb
index 7897db48e0..3871c628fe 100644
--- a/lib/yaml/types.rb
+++ b/lib/yaml/types.rb
@@ -45,7 +45,7 @@ module YAML
class Object
def self.tag_subclasses?; false; end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
@ivars.each do |k,v|
map.add( k, v )
@@ -123,7 +123,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self.object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
@@ -173,7 +173,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self.object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )