summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network
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/network
parent0e7e16d19b12cf7748215d3dd3adf5190fb90d20 (diff)
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/network')
-rw-r--r--lib/puppet/network/format_handler.rb10
1 files changed, 9 insertions, 1 deletions
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