summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-24 14:10:39 -0500
committerLuke Kanies <luke@madstop.com>2008-08-26 22:40:40 -0700
commit90e70227b0bb7cfd104ae34de8f7c2b7250edb09 (patch)
treed94b5b375b5ea4a0532ef49dafd00eab5569d85c /lib/puppet
parent5a195e0c06daa2bfa008cfd94c660e50b9d0ae56 (diff)
downloadpuppet-90e70227b0bb7cfd104ae34de8f7c2b7250edb09.tar.gz
puppet-90e70227b0bb7cfd104ae34de8f7c2b7250edb09.tar.xz
puppet-90e70227b0bb7cfd104ae34de8f7c2b7250edb09.zip
Adding weights to network formats, and sorting them based on the weight.
This way the new hackish RAW format will only ever be used if it's specifically chosen. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-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