diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 10:58:55 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 10:58:55 -0700 |
commit | d3bfc7a71256f84d4ce1b7e31b032739f02dfb55 (patch) | |
tree | dd9ff7addd7c5c2693b37790a676637768030263 /lib | |
parent | 4d047de2c59b71bbe6b4d438970b2c93012662b4 (diff) | |
download | psych-d3bfc7a71256f84d4ce1b7e31b032739f02dfb55.zip |
exceptions move back and forth
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/ruby.rb | 3 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 4 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 8 |
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb index 8831811..f226c84 100644 --- a/lib/psych/ruby.rb +++ b/lib/psych/ruby.rb @@ -4,9 +4,8 @@ require 'date' [ Object, String, Class, Hash, Array, NilClass, Float, FalseClass, TrueClass, - Range, Complex, Rational, Date, Time, Regexp + Range, Complex, Rational, Date, Time, Regexp, Exception # Struct - # Exception ].each do |klass| klass.send(:remove_method, :to_yaml) rescue NameError end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index ab8ef52..d00f72a 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -81,6 +81,10 @@ module Psych h = Hash[*o.children.map { |c| accept c }] Range.new(h['begin'], h['end'], h['excl']) + when "!ruby/exception" + h = Hash[*o.children.map { |c| accept c }] + Exception.new h['message'] + when '!ruby/object:Complex' h = Hash[*o.children.map { |c| accept c }] Complex(h['real'], h['image']) diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 1cfcd33..914a891 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -21,6 +21,14 @@ module Psych raise TypeError, "Can't dump #{target.class}" end + def visit_Exception o + @stack.push append Nodes::Mapping.new(nil, '!ruby/exception', false) + ['message', o.message].each do |m| + accept m + end + @stack.pop + end + def visit_Regexp o append Nodes::Scalar.new(o.inspect, nil, '!ruby/regexp', false) end |