1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove method missing use in respond_to

This commit is contained in:
Yehuda Katz 2008-12-26 13:37:42 -08:00
parent db5a98e6cb
commit 6dc1288111

View file

@ -143,12 +143,31 @@ module ActionController #:nodoc:
custom(@mime_type_priority.first, &block)
end
end
def self.generate_method_for_mime(mime)
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
const = sym.to_s.upcase
class_eval <<-RUBY
def #{sym}(&block) # def html(&block)
if Mime::SET.include?(Mime::#{const}) # if Mime::Set.include?(Mime::HTML)
custom(Mime::#{const}, &block) # custom(Mime::HTML, &block)
else # else
super # super
end # end
end # end
RUBY
end
Mime::SET.each do |mime|
generate_method_for_mime(mime)
end
def method_missing(symbol, &block)
mime_constant = symbol.to_s.upcase
if Mime::SET.include?(Mime.const_get(mime_constant))
custom(Mime.const_get(mime_constant), &block)
mime_constant = Mime.const_get(symbol.to_s.upcase)
if Mime::SET.include?(mime_constant)
self.class.generate_method_for_mime(mime_constant)
send(symbol, &block)
else
super
end