From 021f3d24f32dbad98c72cd5c36ff0b511be07a64 Mon Sep 17 00:00:00 2001 From: Mircea Pricop Date: Fri, 6 Jul 2012 17:19:20 +0200 Subject: Prevent conflict between mime types and Object methods Assuming the type ":touch", Collector.new was calling send(:touch), which instead of triggering method_missing and generating a new collector method, actually invoked the private method `touch` inherited from Object. By generating the method for each mime type as it is registered, the private methods on Object can never be reached by `send`, because the `Collector` will have them before `send` is called on it. To do this, a callback mechanism was added to Mime::Type This allows someone to add a callback for whenever a new mime type is registered. The callback then gets called with the new mime as a parameter. This is then used in AbstractController::Collector to generate new collector methods after each mime is registered. --- actionpack/lib/abstract_controller/collector.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb index 492329c401..09b9e7ddf0 100644 --- a/actionpack/lib/abstract_controller/collector.rb +++ b/actionpack/lib/abstract_controller/collector.rb @@ -16,6 +16,10 @@ module AbstractController generate_method_for_mime(mime) end + Mime::Type.register_callback do |mime| + generate_method_for_mime(mime) unless self.instance_methods.include?(mime.to_sym) + end + protected def method_missing(symbol, &block) -- cgit v1.2.3