summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-01-09 13:28:08 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-01-09 13:28:08 -0800
commit28e6e8b8aa606fd67a3a1e02ee08d2f6b24b185d (patch)
tree0ec7a42881a70c4b8a6d6d44ee9da0a175db5f35
parentbbd6eb07afd3961436b17a1a9c2c4b3606531cdd (diff)
downloadpsych-28e6e8b8aa606fd67a3a1e02ee08d2f6b24b185d.tar.gz
Refactor exception dumping
-rw-r--r--lib/psych/visitors/yaml_tree.rb45
1 files changed, 17 insertions, 28 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index ed8d9e2..bc7d235 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/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")