summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-11-17 20:01:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2009-11-17 20:01:16 -0800
commit83ff66422fd23f883a90a65b25644267a27e25bf (patch)
treeeee597e16bc7387985b21520f3634bdba21340f3
parentccc1107595545a7947080d919529102d3e8c6dfe (diff)
downloadpsych-83ff66422fd23f883a90a65b25644267a27e25bf.zip
adding a method for fetching private instance variables
-rw-r--r--ext/psych/psych.c1
-rw-r--r--ext/psych/psych.h2
-rw-r--r--ext/psych/to_ruby.h2
-rw-r--r--ext/psych/yaml_tree.c23
-rw-r--r--ext/psych/yaml_tree.h8
-rw-r--r--lib/psych/visitors/yaml_tree.rb11
6 files changed, 43 insertions, 4 deletions
diff --git a/ext/psych/psych.c b/ext/psych/psych.c
index a218117..3333ab1 100644
--- a/ext/psych/psych.c
+++ b/ext/psych/psych.c
@@ -26,4 +26,5 @@ void Init_psych()
Init_psych_parser();
Init_psych_emitter();
Init_psych_to_ruby();
+ Init_psych_yaml_tree();
}
diff --git a/ext/psych/psych.h b/ext/psych/psych.h
index eea82f8..76a826b 100644
--- a/ext/psych/psych.h
+++ b/ext/psych/psych.h
@@ -6,6 +6,8 @@
#include <parser.h>
#include <emitter.h>
+#include <to_ruby.h>
+#include <yaml_tree.h>
extern VALUE mPsych;
diff --git a/ext/psych/to_ruby.h b/ext/psych/to_ruby.h
index d4936a8..7b8e757 100644
--- a/ext/psych/to_ruby.h
+++ b/ext/psych/to_ruby.h
@@ -3,6 +3,6 @@
#include <psych.h>
-void Init_psych_to_ruby();
+void Init_psych_to_ruby(void);
#endif
diff --git a/ext/psych/yaml_tree.c b/ext/psych/yaml_tree.c
new file mode 100644
index 0000000..500883d
--- /dev/null
+++ b/ext/psych/yaml_tree.c
@@ -0,0 +1,23 @@
+#include <psych.h>
+
+VALUE cPsychVisitorsYamlTree;
+
+/*
+ * call-seq: private_iv_get(target, prop)
+ *
+ * Get the private instance variable +prop+ from +target+
+ */
+static VALUE private_iv_get(VALUE self, VALUE target, VALUE prop)
+{
+ return rb_attr_get(target, rb_intern(StringValuePtr(prop)));
+}
+
+void Init_psych_yaml_tree(void)
+{
+ VALUE psych = rb_define_module("Psych");
+ VALUE visitors = rb_define_module_under(psych, "Visitors");
+ VALUE visitor = rb_define_class_under(visitors, "Visitor", rb_cObject);
+ cPsychVisitorsYamlTree = rb_define_class_under(visitors, "YAMLTree", visitor);
+
+ rb_define_private_method(cPsychVisitorsYamlTree, "private_iv_get", private_iv_get, 2);
+}
diff --git a/ext/psych/yaml_tree.h b/ext/psych/yaml_tree.h
new file mode 100644
index 0000000..4628a69
--- /dev/null
+++ b/ext/psych/yaml_tree.h
@@ -0,0 +1,8 @@
+#ifndef PSYCH_YAML_TREE_H
+#define PSYCH_YAML_TREE_H
+
+#include <psych.h>
+
+void Init_psych_yaml_tree(void);
+
+#endif
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 0f0e3ba..57d23e2 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -62,11 +62,16 @@ module Psych
end
def visit_Exception o
- tag = ['!ruby/exception', o.class.name].compact.join(':')
+ tag = ['!ruby/exception', o.class.name].join ':'
@stack.push append Nodes::Mapping.new(nil, tag, false)
- ['message', o.message].each do |m|
- accept m
+ {
+ 'message' => private_iv_get(o, 'mesg'),
+ 'backtrace' => private_iv_get(o, 'backtrace'),
+ }.each do |k,v|
+ next unless v
+ append Nodes::Scalar.new k
+ accept v
end
if o.respond_to? :to_yaml_properties