summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-01-09 13:28:08 -0800
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-06-25 15:56:20 +0900
commitf770a5be66412fcbdb238db950c80367100a257e (patch)
treecec9b8bcce43785873cece913fd6ca52fffac609 /ext/psych
parent4bd190942710725a79ca61fb30cff152888b55d0 (diff)
Refactor exception dumping
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb45
1 files changed, 17 insertions, 28 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index ed8d9e2dfe..bc7d2352e4 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -181,37 +181,11 @@ module Psych
end
def visit_Exception o
- tag = ['!ruby/exception', o.class.name].join ':'
-
- @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
-
- msg = private_iv_get(o, 'mesg')
-
- if msg
- @emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
- accept msg
- end
-
- dump_ivars o
-
- @emitter.end_mapping
+ dump_exception o, private_iv_get(o, 'mesg')
end
def visit_NameError o
- tag = ['!ruby/exception', o.class.name].join ':'
-
- @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
-
- msg = o.message.to_s
-
- if msg
- @emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
- accept msg
- end
-
- dump_ivars o
-
- @emitter.end_mapping
+ dump_exception o, o.message.to_s
end
def visit_Regexp o
@@ -488,6 +462,21 @@ module Psych
def dump_list o
end
+ def dump_exception o, msg
+ tag = ['!ruby/exception', o.class.name].join ':'
+
+ @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
+
+ if msg
+ @emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
+ accept msg
+ end
+
+ dump_ivars o
+
+ @emitter.end_mapping
+ end
+
def format_time time
if time.utc?
time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")