Much better. :)
+1
On Mar 25, 2010, at 4:26 PM, Markus Roberts wrote:
The original pure ruby yaml patch missed some edge cases;
specifically, classes
that were modified by the syck version to directly call it and thus
never
reached the pure ruby version. This adds monkey patches to all of
those case
which we might reasonably care about (omitting, for example, calls
within the
syck version to itself) and tests which show that the monkey patch
works.
Signed-off-by: Markus Roberts <[email protected]>
---
lib/puppet/util/monkey_patches.rb | 10 +++++---
spec/unit/util/zaml.rb | 38 ++++++++++++++++++++++++++++
+++++++++
2 files changed, 44 insertions(+), 4 deletions(-)
create mode 100644 spec/unit/util/zaml.rb
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/
monkey_patches.rb
index b7f8a7b..c93d6ff 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -19,11 +19,13 @@ class Symbol
end
end
-class Object
- def to_yaml
- ZAML.dump(self)
+[Object, Exception, Integer, Struct, Date, Time, Range, Regexp,
Hash, Array, Float, String, FalseClass, TrueClass, Symbol, NilClass,
Class].each { |cls|
+ cls.class_eval do
+ def to_yaml
+ ZAML.dump(self)
+ end
end
-end
+}
def YAML.dump(*args)
ZAML.dump(*args)
diff --git a/spec/unit/util/zaml.rb b/spec/unit/util/zaml.rb
new file mode 100644
index 0000000..1f21c4e
--- /dev/null
+++ b/spec/unit/util/zaml.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?
(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/
spec_helper.rb") }
+
+require 'puppet/util/monkey_patches'
+
+describe "Pure ruby yaml implementation" do
+ {
+ 7 => "--- 7",
+ 3.14159 => "--- 3.14159",
+ 'test' => "--- test",
+ [] => "--- []",
+ :symbol => "--- !ruby/sym symbol",
+ {:a => "A"} => "--- \n !ruby/sym a: A"
+ }.each { |o,y|
+ it "should convert the #{o.class} #{o.inspect} to yaml" do
+ o.to_yaml.should == y
+ end
+ it "should produce yaml for the #{o.class} #{o.inspect}
that can be reconstituted" do
+ YAML.load(o.to_yaml).should == o
+ end
+ }
+ #
+ # Can't test for equality on raw objects
+ {
+ Object.new => "--- !ruby/object {}",
+ [Object.new] => "--- \n - !ruby/object {}",
+ {Object.new => Object.new} => "--- \n ? !ruby/object {}
\n : !ruby/object {}"
+ }.each { |o,y|
+ it "should convert the #{o.class} #{o.inspect} to yaml" do
+ o.to_yaml.should == y
+ end
+ it "should produce yaml for the #{o.class} #{o.inspect}
that can be reconstituted" do
+ lambda { YAML.load(o.to_yaml) }.should_not raise_error
+ end
+ }
+end
+
--
1.6.4
--
You received this message because you are subscribed to the Google
Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]
.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en
.
--
To my embarrassment I was born in bed with a lady.
--Wilson Mizner
---------------------------------------------------------------------
Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199
--
You received this message because you are subscribed to the Google Groups "Puppet
Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.