module Patches module MyControllerPatch def self.included(base) # base.extend(ClassMethods) # base.send(:include, InstanceMethods) base.class_eval do unloadable # alias_method_chain :account, :ext end end module ClassMethods end module InstanceMethods # ext def account_with_ext if request.post? # User.current.pref[:no_self_notified_closed] = (params[:no_self_notified_closed] == '1') end # account account_without_ext end end end end
module Patches module IssuePatch def self.included(base) … base.class_eval do unloadable # alias_method :recipients, :recipients_ext alias_method :watcher_recipients, :watcher_recipients_ext end end … module InstanceMethods # def recipients_ext # @status = IssueStatus.find_by_id(self.status_id) notified = project.notified_users # ( allow_notify_closed) notified << author if author && author.active? && author.notify_about?(self) && allow_notify_closed?(author) if assigned_to if assigned_to.is_a?(Group) notified += assigned_to.users.select { |u| u.active? && u.notify_about?(self) && allow_notify_closed?(u) } else notified << assigned_to if assigned_to.active? && assigned_to.notify_about?(self) && allow_notify_closed?(assigned_to) end end notified.uniq! notified.reject! { |user| !visible?(user) } notified.collect(&:mail) end # def watcher_recipients_ext notified = watcher_users.active notified.reject! { |user| user.mail_notification == 'none' || allow_notify_closed?(user) === false } if respond_to?(:visible?) notified.reject! { |user| !visible?(user) } end notified.collect(&:mail).compact end private # , def allow_notify_closed?(user) (user.pref[:no_self_notified_closed] && @status.is_closed?) ? false : true end end end end
# dispatcher require 'dispatcher' Dispatcher.to_prepare do MyController.send(:include, Patches::MyControllerPatch) UsersController.send(:include, Patches::UsersControllerPatch) Issue.send(:include, Patches::IssuePatch) end
Source: https://habr.com/ru/post/142584/
All Articles