diff options
-rw-r--r-- | actionpack/lib/action_controller/mime_responds.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/mime_type_test.rb | 5 |
3 files changed, 10 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index e1e6790381..e297cf8b07 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -94,7 +94,7 @@ module ActionController #:nodoc: # and accept Rails' defaults, life will be much easier. def respond_to(*types, &block) raise ArgumentError, "respond_to takes either types or a block, never bot" unless types.any? ^ block - block ||= lambda { |responder| types.each { |type| responder.send(type) } } + block ||= lambda { |responder| types.each { |type| responder.known(type) } } responder = Responder.new(block.binding) block.call(responder) responder.respond @@ -132,12 +132,8 @@ module ActionController #:nodoc: end end - for mime_type in %w( all html js xml rss atom yaml ) - eval <<-EOT - def #{mime_type}(&block) - custom(Mime::#{mime_type.upcase}, &block) - end - EOT + def known(mime_type_extension, &block) + custom(Mime.const_get(mime_type_extension.to_s.upcase), &block) end def any(*args, &block) diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index a2233477bd..7c1448029d 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -33,7 +33,8 @@ module Mime def register(string, symbol, synonyms = []) Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms) - LOOKUP[string] = Mime.send :const_get, symbol.to_s.upcase + SET << Mime.send(:const_get, symbol.to_s.upcase) + LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last end def parse(accept_header) @@ -126,6 +127,7 @@ module Mime ATOM = Type.new "application/atom+xml", :atom YAML = Type.new "application/x-yaml", :yaml, %w( text/yaml ) + SET = [ ALL, TEXT, HTML, JS, ICS, XML, RSS, ATOM, YAML ] LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" } diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index 436251b0f9..65acbbf36e 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -24,7 +24,10 @@ class MimeTypeTest < Test::Unit::TestCase def test_custom_type Mime::Type.register("image/gif", :gif) - assert_nothing_raised { Mime::GIF } + assert_nothing_raised do + Mime::GIF + assert_equal Mime::GIF, Mime::SET.last + end Mime.send :remove_const, :GIF end end
\ No newline at end of file |