summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-30 22:19:01 -0500
committerLuke Kanies <luke@madstop.com>2008-07-30 22:19:01 -0500
commit29d704c3f7d69f04e27aae69f4c1ef9dfc979972 (patch)
tree0e2dacf7c12cd6844277f14ea8153d9d52d5143d /lib/puppet
parentc55acee2264b126541ea26d49e1994b263568548 (diff)
downloadpuppet-29d704c3f7d69f04e27aae69f4c1ef9dfc979972.tar.gz
puppet-29d704c3f7d69f04e27aae69f4c1ef9dfc979972.tar.xz
puppet-29d704c3f7d69f04e27aae69f4c1ef9dfc979972.zip
The REST formats are now fully functional, with yaml and marshal support.
This is the last of the REST plumbing. The only flaw right now is that the formats are managed by name rather than by mimetype, which I'll fix next. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/network/format_handler.rb12
-rw-r--r--lib/puppet/network/formats.rb54
2 files changed, 52 insertions, 14 deletions
diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index cf19c02a7..4c9f4e59e 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -63,14 +63,6 @@ module Puppet::Network::FormatHandler
def supported_formats
format_handler.formats.collect { |f| format_handler.format(f) }.find_all { |f| f.supported?(self) }.collect { |f| f.name }
end
-
- def from_marshal(text)
- Marshal.load(text)
- end
-
- def from_yaml(text)
- YAML.load(text)
- end
end
module InstanceMethods
@@ -83,10 +75,6 @@ module Puppet::Network::FormatHandler
def support_format?(name)
self.class.support_format?(name)
end
-
- def to_marshal(instance)
- Marshal.dump(instance)
- end
end
end
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index 640a24485..79e2860af 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -1,4 +1,54 @@
require 'puppet/network/format_handler'
-Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml")
-Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal")
+Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do
+ # Yaml doesn't need the class name; it's serialized.
+ def intern(klass, text)
+ YAML.load(text)
+ end
+
+ # Yaml doesn't need the class name; it's serialized.
+ def intern_multiple(klass, text)
+ YAML.load(text)
+ end
+
+ def render(instance)
+ instance.to_yaml
+ end
+
+ # Yaml monkey-patches Array, so this works.
+ def render_multiple(instances)
+ instances.to_yaml
+ end
+
+ # Everything's supported
+ def supported?(klass)
+ true
+ end
+end
+
+
+Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do
+ # Yaml doesn't need the class name; it's serialized.
+ def intern(klass, text)
+ Marshal.load(text)
+ end
+
+ # Yaml doesn't need the class name; it's serialized.
+ def intern_multiple(klass, text)
+ Marshal.load(text)
+ end
+
+ def render(instance)
+ Marshal.dump(instance)
+ end
+
+ # Yaml monkey-patches Array, so this works.
+ def render_multiple(instances)
+ Marshal.dump(instances)
+ end
+
+ # Everything's supported
+ def supported?(klass)
+ true
+ end
+end