Make a patch inside plugin
Added by Luis Serrano Aranda almost 13 years ago
Make a patch inside plugin
I want make I patch inside my plugin of the method def default_columns_names (app/models/query.rb), I write but don't patch the method.
Could you help me ?
This is the code:
improve_issues.ini
require 'redmine' require 'base64' require 'dispatcher' Dispatcher.to_prepare :improve_issues do # Patches to the Redmine core. Query.send(:include, QueryPatch) end ....
This is the query_patch.rb
require_dependency "query" module QueryPatch def self.included(base) base.send(:include, InstanceMethods) base.class_eval do unloadable alias_method_chain :default_columns_names, :patch end end module InstanceMethods def default_columns_names_with_patch @default_columns_names ||= begin default_columns = Setting.issue_list_default_columns.map(&:to_sym) if !default_columns.index (:status) default_columns.insert (-1,:status) end project.present? ? default_columns : [:project] | default_columns end end end end
This Is to try to add default columns in the issue list, programmed in the role.
These lines are working inside the core:
if !default_columns.index (:status) default_columns.insert (-1,:status) end
Adding column status.
Replies (5)
RE: Make a patch inside plugin - Added by Evgeny Tsirkin almost 13 years ago
Where from come the idea to put code in improve_issues.ini?
I am just interested .
While creating the plugin I put the initialization code in init.rb.
Why improve_issues.ini?
I am actually putting the require of the lib patch file in init.rb.
Not sure if this is really needed but it works.
In your case maybe this will help :
require 'query_patch'
Ah,and maybe you should put your query_patch.rb in the lib directory.
Yes, at least as I understand ,the engines should pick up the patch from the
models directory.
But all the examples I have seen uses lib location.
Maybe someone with more internal knowledge of redmine & engines could
shed some light on the right location of model patch.
Good luck.
RE: Make a patch inside plugin - Added by Luis Serrano Aranda almost 13 years ago
I have almost made the plugin ... Need to improve things but it works just about everything. I joined functionality of plugins that interest me, and added my code ...
I just have a detail, I need a patch work or not depending on whether the module is enabled or not. As I can do?
I've tried (inside init.r and similar lines inside the patch file)
if module_enabled? (: ImproveViewColumns)
Query.send (: include, ColumnsPatch)
end
But don't work, could you helpme
When I finish the plugin will do public. Thanks in advance
RE: Make a patch inside plugin - Added by Luis Serrano Aranda almost 13 years ago
Once solved this, only I do to improve the treatment of the views ...
but do not overwriting them with hooks and if you have the hook necessary, override the view by simply adding the hook
RE: Make a patch inside plugin - Added by Luis Serrano Aranda almost 13 years ago
Sorry for my english, google translator helpe but sometimes does not translate properly
RE: Make a patch inside plugin - Added by Luis Serrano Aranda almost 13 years ago
And sorry in my plugin the init file is init.rb not improve_issues.ini. I do not know why I wrote this name in the message :P