Determine if Module is Turned On
Added by Derric Atzrott over 11 years ago
So after a fair amount of effort (ruby/rails noob here), I finally managed to figure out duck-punching/monkey-patching. The next thing I need to do with my Redmine plugin is run some code in the controller based on whether or not a module is enabled in the project.
Currently I have the following code within ./lib/projects_controller_patch.rb:
module ProjectsControllerPatch def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do alias_method_chain :show, :ps end end module InstanceMethods def show_with_ps #CODE HERE THAT NEEDS TO BE RUN DEPENDING ON IF THE MODULE IS TURNED ON return show_without_ps end end end ProjectsController.send(:include, ProjectsControllerPatch)
Would anyone be able to help me work out how to determine if a module is turned on for the current project? Would you be willing to also explain why it works?
Thank you,
Derric Atzrott
EDIT: This is for Redmine 2.x
Replies (2)
RE: Determine if Module is Turned On - Added by Derric Atzrott over 11 years ago
I've managed to work out how to determine if a module is enabled:
@Project.module_enabled?("MODULE NAME") should either return an object for the module (if it is enabled) or nil (if it is disabled).
This was determined with a little experimenting using the console and also by browsing through app/models/project.rb (available here: http://www.redmine.org/projects/redmine/repository/entry/branches/2.3-stable/app/models/project.rb)
You can see the code for module_enabled? beginning on line 610.
RE: Determine if Module is Turned On - Added by Jean-Baptiste Barth over 11 years ago
Started Plugin_FAQ, don't hesitate to improve it if you want.