Project

General

Profile

Defect #6324 » init.rb

000_pluginloader - Michael Krupp, 2016-02-03 18:35

 
1
# coding: utf-8
2

    
3
module RedminePluginloader
4
module Patches
5
  module PluginloaderPatch
6

    
7
    def self.included(base)
8
      base.extend ClassMethods
9
      base.send(:include, InstanceMethods)
10
      base.class_eval do
11
        cattr_accessor :plugin_requirements
12

    
13
        class << self
14
          alias_method_chain :register, :pluginloader
15
        end
16

    
17
        alias_method_chain :requires_redmine_plugin, :pluginloader
18
      end
19
    end
20

    
21
    module InstanceMethods
22
      def requires_redmine_plugin_with_pluginloader(plugin_name, arg, &block)
23
        self.class.plugin_requirements << [id, plugin_name, arg]
24
      end
25
    end
26

    
27
    module ClassMethods
28
      def register_with_pluginloader(id, &block)
29
        self.plugin_requirements ||= [ ]
30
        register_without_pluginloader(id, &block)
31
      end
32

    
33
      def check_plugin_requirements
34
        self.plugin_requirements.each do |id, dep, arg|
35
          plugin = self.find(id)
36
          begin
37
            plugin.requires_redmine_plugin_without_pluginloader(dep, arg)
38
          rescue ::Redmine::PluginNotFound => e
39
            raise ::Redmine::PluginRequirementError,
40
                "#{id} plugin requires the #{dep} plugin, which is not installed.",
41
                $!.backtrace
42
          end
43
        end
44
      end
45
    end
46
  end
47

    
48
  unless ::Redmine::Plugin.included_modules.include?(PluginloaderPatch)
49
    ::Redmine::Plugin.send(:include, PluginloaderPatch)
50
  end
51
end
52
end
(6-6/8)