1 module RedminePublications
2 # Patches Redmine's Issues dynamically. Adds a +after_save+ filter.
5 def self.included(base) # :nodoc:
6 base.extend(ClassMethods)
8 base.send(:include, InstanceMethods)
10 # Same as typing in the class
12 unloadable # Send unloadable so it will not be unloaded in development
13 after_save :update_publication
21 module InstanceMethods
23 def update_publication
24 if (self.action == 'A') and (self.changeset.repository.project_id == Setting.plugin_redmine_publications[:project].to_i)
25 regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern])
26 match = self.path.match(regexp)
28 Rails.logger.info('[INFO] Adding publication: "' << match[1])
29 Publication.find_or_create_by_name(:name => match[1],
30 :source_file => self.path, :repository_id => self.changeset.repository.id )