[Plugins] Strange bug with plugin load ordering
I developing two plugins thats patch some redmine classes. First plugin is redmine_repository plugin, it is patching RepositoryController. Second plugin is redmine_sidebar plugin, that patching ApplicationHelper. The patching like this
module RepositoriesControllerPatch def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) end module ClassMethods end module InstanceMethods # there is some methods end end RepositoriesController.send(:include, RepositoriesControllerPatch)
module SidebarApplicationHelperPatch def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) end module ClassMethods end module InstanceMethods # there is some methods end end ApplicationHelper.send(:include, SidebarApplicationHelperPatch)
In default plugins load in ordering: redmine_repository is first, redmine_sidebar is second. In this case the error occured
undefined method `show_sidebar?' for #<ActionView::Base:0x7fcbd8d91128>
show_sidebar?method is defined in SidebarApplicationHelperPatch.
If i insert into
enviroment.rbplugin loading order
config.plugins = [ :all, :redmine_sidebar, :redmine_repository ]
there is no error occured.
Why? Can someone explain me because of what is happening?
redmine_repository is loaded first, the
RepositoriesController is already instantiated when
redmine_sidebar is loaded, and thus the patching of
ApplicationHelper doesn't get passed to
One solution we use against this is:
ApplicationController.subclasses.each do |subclass| Kernel.const_get(subclass).send(:include, SomePlugin::ApplicationControllerPatch) end
Not sure how good that would work with the
ApplicationHelper, but you get the idea.