summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-10-09 15:23:19 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-10-17 12:23:33 +1100
commitbca3b70437666a8b840af032cab20fc1ea4f18a2 (patch)
tree0cde5cd7b39fc5a5e41b636d1f55a7ed71d6518b /lib/puppet/util
parentce46be5773656f68eddc7edd6212e283b46f9320 (diff)
downloadpuppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.tar.gz
puppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.tar.xz
puppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.zip
Bundling of pure ruby json lib as "pson"
Bundeling and renaming the pure ruby json library to addresses a number of cross version serliaization bugs (#2615, et al). This patch adds a subset of the files from the json_pure gem to lib/puppet/external/pson (renamed to avoid conflicts with rails) so that we will always have a known-good erialization format available. The pure ruby json gem as distibuted defers to the compiled version if it is installed. This is problematic in some circumstances so the files that have been brought over have been modified to always and only use the bundled version. It's a large patch, so here's a breakdown of the change categories: The majority of the lines are only marginally interesting: * The json lib itself (in lib/puppet/external/pson) make up the bulk of the lines. * Renaming of json to pson make up the second largest group. Somewhat more interesting are the following, which can be located by searching the diffs for the indicated strings: * Adjusting tests to reflect the changes * Changing the encoding/decoding behavior so that nested structures (e.g. resources) don't serialize as escaped strings. This should make it much easier to process the results with external tools, if needed. Search for "to_pson" and "to_pson_data_hash" * Cleaning up the envelope/metadata * Now provides a document_type (as opposed to a ruby class name) by using a symple registration scheme instead of constant lookup (search for "document_type") * Added an api_version (search for "api_version") * Added a hash for document metadata (search for "metadata") * Removing the yaml monkeypatch and instead disabling yaml serialization on ruby 1.8.1 in favor of pson (search for "yaml") * Cleaning up the json/rails feature interaction (they're now totally independent) (search for "feature")
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/monkey_patches.rb43
-rw-r--r--lib/puppet/util/pson.rb (renamed from lib/puppet/util/json.rb)12
2 files changed, 6 insertions, 49 deletions
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb
index 817b813f0..e69de29bb 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -1,43 +0,0 @@
-#
-# Monkey patches to ruby classes for compatibility
-#
-#
-# In earlier versions of ruby (e.g. 1.8.1) yaml serialized symbols with an explicit
-# type designation. Later versions understand the explicit form in addition to the
-# implicit "literal" form (e.g. :symbol) which they produce.
-#
-# This causes problems when the puppet master and the client are running on different
-# versions of ruby; the newer version can produce yaml that it's older partner can't
-# decypher.
-#
-# This patch causes newer versions to produce the older encoding for Symbols. It is
-# only applied if the existing library does not already produce them. Thus it will
-# not be applied on older rubys and it will not be applied more than once. It also
-# checks that it has been applied to a version which support it and, if not reverts
-# to the original.
-#
-require "yaml"
-
-if :test.to_yaml !~ %r{!ruby/sym}
- class Symbol
- if !respond_to? :original_to_yaml
- alias :original_to_yaml :to_yaml
- def to_yaml(opts={})
- YAML::quick_emit(nil,opts) { |out|
- if out.respond_to? :scalar
- # 1.8.5 through 1.8.8, possibly others
- out.scalar("tag:ruby:sym", to_s,:to_yaml_style)
- elsif out.respond_to? :<<
- # 1.8.2, possibly others
- out << "!ruby/sym "
- self.id2name.to_yaml( :Emitter => out )
- else
- # go back to the base version if neither of the above work
- alias :to_yaml :original_to_yaml
- to_yaml(opts)
- end
- }
- end
- end
- end
-end
diff --git a/lib/puppet/util/json.rb b/lib/puppet/util/pson.rb
index d6f1a2f75..3356437b3 100644
--- a/lib/puppet/util/json.rb
+++ b/lib/puppet/util/pson.rb
@@ -1,13 +1,13 @@
-# A simple module to provide consistency between how we use JSON and how
+# A simple module to provide consistency between how we use PSON and how
# ruby expects it to be used. Basically, we don't want to require
# that the sender specify a class.
-# Ruby wants everyone to provide a 'json_class' field, and the JSON support
+# Ruby wants everyone to provide a 'type' field, and the PSON support
# requires such a field to track the class down. Because we use our URL to
# figure out what class we're working on, we don't need that, and we don't want
# our consumers and producers to need to know anything about our internals.
-module Puppet::Util::Json
- def json_create(json)
- raise ArgumentError, "No data provided in json data" unless json['data']
- from_json(json['data'])
+module Puppet::Util::Pson
+ def pson_create(pson)
+ raise ArgumentError, "No data provided in pson data" unless pson['data']
+ from_pson(pson['data'])
end
end