diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/indirector.rb | 2 | ||||
-rw-r--r-- | lib/puppet/network/format_handler.rb | 10 |
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 |