Hello, I have a question about plugins playing nice together when you have more than one plugin that attempts to override the same rails method. In my case I have written a plugin that provides it''s own form_remote_tag implementation, but I also have another plugin installed that does the same thing. My plugin version does not work though as any form_remote_tag calls are instead being redirected to version in the other plugin (most likely due to being loaded after my plugin). Is there some known way to prevent such issues or to at least warn of them? I can see problems such as this becoming more common as people install more and more plugins. Thanks for any insight, Andrew
On 2006-07-21, at 20:53 , Andrew Kaspick wrote:> ... My plugin version does not work > though as any form_remote_tag calls are instead being redirected to > version in the other plugin (most likely due to being loaded after my > plugin). > > Is there some known way to prevent such issues or to at least warn of > them?You can use alias_method_chain to wrap the original method call, but that relies on both plugins using it, and if you''re not going to use the original call, well, it''s just counter intuivive. Here''s an example MyPlugin::MyModule def self.included base base.alias_method_chain :some_method, :superfun_feature end def some_method_with_superfun_feature do_stuff some_method_without_superfun_feature end end end class WhateverIWantToExtend include MyPlugin::MyModule end You can also hook up to the method_defined ruby callback, and issue a warning whenever a method from your plugin is redefined, or even alias back your method over the new one (evil). class ThingIModified def self.method_added m return unless m == :do_something return unless instance_method(m) != instance_method (:do_something_plugin_version) warn "do_something redefinition attempt. overriding" alias do_something do_something_plugin_version end def do_something_plugin_version; 1 end alias do_something do_something_plugin_version end t = ThingIModified.new class ThingIModified def do_something 2 end end t.do_something
Quick corrections:> MyPlugin::MyModulethat would be: module MyPlugin::MyModule> You can also hook up to the method_defined ruby callbackI meant method_added, as seen in the example code (which is tested, meaning you can run it in irb and see it working)
Thanks for the info, that helps a lot. On 7/21/06, Caio Chassot <lists@v2studio.com> wrote:> Quick corrections: > > > MyPlugin::MyModule > > that would be: > > module MyPlugin::MyModule > > > You can also hook up to the method_defined ruby callback > > I meant method_added, as seen in the example code (which is tested, > meaning you can run it in irb and see it working) > > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >