summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-09 19:07:47 -0700
committerLuke Kanies <luke@madstop.com>2008-07-29 00:47:02 -0500
commit1f15725263812be347c42a2ea3777fee7b2129c9 (patch)
treec0d284d50d67f11c82992372a36f069364e4c31c /lib/puppet
parent0e7e16d19b12cf7748215d3dd3adf5190fb90d20 (diff)
downloadpuppet-1f15725263812be347c42a2ea3777fee7b2129c9.tar.gz
puppet-1f15725263812be347c42a2ea3777fee7b2129c9.tar.xz
puppet-1f15725263812be347c42a2ea3777fee7b2129c9.zip
Using the FormatHandler in indirected classes automatically.
Signed-off-by: Luke Kanies <luke@madstop.com> Changing the FormatHandler#render method to render_to Signed-off-by: Luke Kanies <luke@madstop.com> Adding the ability for the format handler to query supported formats. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector.rb2
-rw-r--r--lib/puppet/network/format_handler.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index 2402b9cbe..1beb68ec0 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -10,6 +10,7 @@ module Puppet::Indirector
require 'puppet/indirector/indirection'
require 'puppet/indirector/terminus'
require 'puppet/indirector/envelope'
+ require 'puppet/network/format_handler'
# Declare that the including class indirects its methods to
# this terminus. The terminus name must be the name of a Puppet
@@ -22,6 +23,7 @@ module Puppet::Indirector
extend ClassMethods
include InstanceMethods
include Puppet::Indirector::Envelope
+ extend Puppet::Network::FormatHandler
# instantiate the actual Terminus for that type and this name (:ldap, w/ args :node)
# & hook the instantiated Terminus into this class (Node: @indirection = terminus)
diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index a69c29232..ab828ad12 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -18,10 +18,18 @@ module Puppet::Network::FormatHandler
def support_format?(name)
respond_to?("from_%s" % name) and instance_methods.include?("to_%s" % name)
end
+
+ def supported_formats
+ instance = instance_methods.collect { |m| m =~ /^to_(.+)$/ and $1 }.compact
+ klass = methods.collect { |m| m =~ /^from_(.+)$/ and $1 }.compact
+
+ # Return the intersection of the two lists.
+ return instance & klass
+ end
end
module InstanceMethods
- def render(format)
+ def render_to(format)
raise ArgumentError, "Format %s not supported" % format unless support_format?(format)
send("to_%s" % format)
end