diff options
Diffstat (limited to 'lib/puppet/util')
| -rw-r--r-- | lib/puppet/util/monkey_patches.rb | 43 | ||||
| -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 |
