summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-03-23 13:43:38 -0500
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitb41d53596cdcb6d7220b93926f6eedf171c09c46 (patch)
treef7616b6197520fdb5f96fe37aa955518d7b26978 /lib/puppet
parent7504f1ede94900ab42cd6e9c4ff9c8a5cb9e65ee (diff)
downloadpuppet-b41d53596cdcb6d7220b93926f6eedf171c09c46.tar.gz
puppet-b41d53596cdcb6d7220b93926f6eedf171c09c46.tar.xz
puppet-b41d53596cdcb6d7220b93926f6eedf171c09c46.zip
Adding filename extension support to formats.
This is toward fixing #1943 - we need the ability to easily convert between file extensions and file formats. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/network/format.rb3
-rw-r--r--lib/puppet/network/format_handler.rb7
-rw-r--r--lib/puppet/network/formats.rb2
3 files changed, 10 insertions, 2 deletions
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index d78124221..7c3cc7bd8 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -7,7 +7,7 @@ class Puppet::Network::Format
include Puppet::Provider::Confiner
attr_reader :name, :mime
- attr_accessor :intern_method, :render_method, :intern_multiple_method, :render_multiple_method, :weight, :required_methods
+ attr_accessor :intern_method, :render_method, :intern_multiple_method, :render_multiple_method, :weight, :required_methods, :extension
def init_attribute(name, default)
if value = @options[name]
@@ -36,6 +36,7 @@ class Puppet::Network::Format
init_attribute(:mime, "text/%s" % name)
init_attribute(:weight, 5)
init_attribute(:required_methods, method_list.keys)
+ init_attribute(:extension, name.to_s)
method_list.each do |method, value|
init_attribute(method, value)
diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index ea8cf35de..a637f8b89 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -51,6 +51,13 @@ module Puppet::Network::FormatHandler
@formats[name.to_s.downcase.intern]
end
+ def self.format_by_extension(ext)
+ @formats.each do |name, format|
+ return format if format.extension == ext
+ end
+ return nil
+ end
+
# Provide a list of all formats.
def self.formats
@formats.keys
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index a98dcbcc5..62569d4b1 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -131,7 +131,7 @@ Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do
end
end
-Puppet::Network::FormatHandler.create(:s, :mime => "text/plain")
+Puppet::Network::FormatHandler.create(:s, :mime => "text/plain", :extension => "txt")
# A very low-weight format so it'll never get chosen automatically.
Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weight => 1) do