Project

General

Profile

Overriding model method

Added by Evgeny Tsirkin about 12 years ago

Dear forum,
I am pretty new to ruby ,so i hope this is not a total newbie question.
I am trying to make it possible to start a workflow from different statuses .
For that i am overriding IssueStatus#update_default .
(maybe this is not the best way to do it ,but let's leave this alone ).
The problem is that although the plugin is loading the method is no overridden - the old one is called.

Here is my issue_status_patch.rb (I am putting it in lib dir of the plugin )
Any help please!

require_dependency 'issue_status'
module IssueStatusPatch
  def self.included(base) # :nodoc:
    base.extend(ClassMethods)
    base.send(:include, InstanceMethods)
    base.logger.debug "PATCHING ISSUE" 
  end

  module ClassMethods
    # Returns the default status for new issues
    def default
      logger.debug "In plugin default" 
      #find(:first, :conditions =>["is_default=?", true])
      find(:all, :conditions =>["is_default=?", true])
    end
  end

  module InstanceMethods
    def update_default_patched
      logger.debug "In plugin update_default" 
      #IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
    end
  end
end

# Add module to Issue
Issue.send(:include, IssueStatusPatch)

And here is the init.rb:

require 'redmine'
require 'issue_status_patch'

Redmine::Plugin.register :redmine_redmine_mutiple_start_issues do
  name 'Redmine Redmine Mutiple Start Issues plugin'
  author 'Tsirkin Evgeny'
  description 'Allow multiple start issue states'
  version '0.0.1'
  url 'http://example.com/path/to/plugin'
  author_url 'http://example.com/about'
end