diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-30 11:09:07 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-07-30 11:09:07 -0500 |
commit | c55acee2264b126541ea26d49e1994b263568548 (patch) | |
tree | c3d6b1cde21815f021504cf83517d9ee89732e1b | |
parent | 8033bd4b7398785048cf789698c1b341049c5983 (diff) | |
download | puppet-c55acee2264b126541ea26d49e1994b263568548.tar.gz puppet-c55acee2264b126541ea26d49e1994b263568548.tar.xz puppet-c55acee2264b126541ea26d49e1994b263568548.zip |
Adding some support for case insensivity in format names.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/network/format.rb | 11 | ||||
-rw-r--r-- | lib/puppet/network/format_handler.rb | 3 | ||||
-rwxr-xr-x | spec/unit/network/format.rb | 9 | ||||
-rwxr-xr-x | spec/unit/network/format_handler.rb | 10 |
4 files changed, 26 insertions, 7 deletions
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 256e9a8d4..7eb2a632f 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -5,17 +5,16 @@ require 'puppet/provider/confiner' class Puppet::Network::Format include Puppet::Provider::Confiner - attr_reader :name - attr_accessor :mime + attr_reader :name, :mime def initialize(name, options = {}, &block) @name = name.to_s.downcase.intern if mime = options[:mime] - @mime = mime + self.mime = mime options.delete(:mime) else - @mime = "text/%s" % name + self.mime = "text/%s" % name end unless options.empty? @@ -40,6 +39,10 @@ class Puppet::Network::Format raise NotImplementedError end + def mime=(mime) + @mime = mime.to_s.downcase + end + def render(instance) return instance.send(render_method) if instance.respond_to?(render_method) raise NotImplementedError diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb index 6700c42a8..cf19c02a7 100644 --- a/lib/puppet/network/format_handler.rb +++ b/lib/puppet/network/format_handler.rb @@ -21,7 +21,7 @@ module Puppet::Network::FormatHandler end def self.format(name) - @formats[name] + @formats[name.to_s.downcase.intern] end # Provide a list of all formats. @@ -31,6 +31,7 @@ module Puppet::Network::FormatHandler # Return a format capable of handling the provided mime type. def self.mime(mimetype) + mimetype = mimetype.to_s.downcase @formats.values.find { |format| format.mime == mimetype } end diff --git a/spec/unit/network/format.rb b/spec/unit/network/format.rb index b746f8080..b960a3f73 100755 --- a/spec/unit/network/format.rb +++ b/spec/unit/network/format.rb @@ -34,8 +34,8 @@ describe Puppet::Network::Format do Puppet::Network::Format.new(:My_Format).name.should == :my_format end - it "should be able to set its mime type at initialization" do - format = Puppet::Network::Format.new(:my_format, :mime => "foo/bar") + it "should be able to set its downcased mime type at initialization" do + format = Puppet::Network::Format.new(:my_format, :mime => "Foo/Bar") format.mime.should == "foo/bar" end @@ -73,6 +73,11 @@ describe Puppet::Network::Format do it "should not consider a class to be supported unless it has the individual and multiple methods for rendering and interning" do Puppet::Network::Format.new(:yaml).should_not be_supported(String) end + + it "should always downcase mimetypes" do + @format.mime = "Foo/Bar" + @format.mime.should == "foo/bar" + end end describe "when converting between instances and formatted text" do diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb index b5f981b1c..35e996516 100755 --- a/spec/unit/network/format_handler.rb +++ b/spec/unit/network/format_handler.rb @@ -101,11 +101,21 @@ describe Puppet::Network::FormatHandler do Puppet::Network::FormatHandler.format(:by_name).should equal(format) end + it "should be able to retrieve formats by name irrespective of case and class" do + format = Puppet::Network::FormatHandler.create(:by_name) + Puppet::Network::FormatHandler.format(:By_Name).should equal(format) + end + it "should be able to retrieve a format by mime type" do format = Puppet::Network::FormatHandler.create(:by_name, :mime => "foo/bar") Puppet::Network::FormatHandler.mime("foo/bar").should equal(format) end + it "should be able to retrieve a format by mime type irrespective of case" do + format = Puppet::Network::FormatHandler.create(:by_name, :mime => "foo/bar") + Puppet::Network::FormatHandler.mime("Foo/Bar").should equal(format) + end + it "should be able to return all formats" do one = stub 'one', :name => :one two = stub 'two', :name => :two |