summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/network')
-rw-r--r--lib/puppet/network/format.rb9
-rw-r--r--lib/puppet/network/format_handler.rb5
-rw-r--r--lib/puppet/network/formats.rb3
3 files changed, 14 insertions, 3 deletions
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index 3e0a7d8aa..21aead7cc 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -5,7 +5,7 @@ require 'puppet/provider/confiner'
class Puppet::Network::Format
include Puppet::Provider::Confiner
- attr_reader :name, :mime
+ attr_reader :name, :mime, :weight
def initialize(name, options = {}, &block)
@name = name.to_s.downcase.intern
@@ -17,6 +17,13 @@ class Puppet::Network::Format
self.mime = "text/%s" % name
end
+ if weight = options[:weight]
+ @weight = weight
+ options.delete(:weight)
+ else
+ @weight = 5
+ end
+
unless options.empty?
raise ArgumentError, "Unsupported option(s) %s" % options.keys
end
diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index 4c9f4e59e..f3c3380e1 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -61,7 +61,10 @@ module Puppet::Network::FormatHandler
end
def supported_formats
- format_handler.formats.collect { |f| format_handler.format(f) }.find_all { |f| f.supported?(self) }.collect { |f| f.name }
+ format_handler.formats.collect { |f| format_handler.format(f) }.find_all { |f| f.supported?(self) }.collect { |f| f.name }.sort do |a, b|
+ # It's an inverse sort -- higher weight formats go first.
+ format_handler.format(b).weight <=> format_handler.format(a).weight
+ end
end
end
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index c2a8b7ab6..85e8ce6f8 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -55,7 +55,8 @@ end
Puppet::Network::FormatHandler.create(:s, :mime => "text/plain")
-Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw") do
+# A very low-weight format so it'll never get chosen automatically.
+Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weight => 1) do
def intern_multiple(klass, text)
raise NotImplementedError
end