Class: Redmine::PluginLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/plugin_loader.rb

Class Method Summary collapse

Class Method Details

.add_autoload_pathsObject



124
125
126
127
128
129
130
131
132
133
# File 'lib/redmine/plugin_loader.rb', line 124

def self.add_autoload_paths
  directories.each do |directory|
    # Add the plugin directories to rails autoload paths
    engine_cfg = Rails::Engine::Configuration.new(directory.to_s)
    engine_cfg.paths.add 'lib', eager_load: true
    engine_cfg.eager_load_paths.each do |dir|
      Rails.autoloaders.main.push_dir dir
    end
  end
end

.create_assets_reloaderObject



93
94
95
96
97
98
99
100
101
# File 'lib/redmine/plugin_loader.rb', line 93

def self.create_assets_reloader
  plugin_assets_dirs = {}
  directories.each do |dir|
    plugin_assets_dirs[dir.assets_dir] = ['*']
  end
  ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
    mirror_assets
  end
end

.directoriesObject



135
136
137
# File 'lib/redmine/plugin_loader.rb', line 135

def self.directories
  @plugin_directories
end

.loadObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/redmine/plugin_loader.rb', line 103

def self.load
  setup
  add_autoload_paths

  Rails.application.config.to_prepare do
    PluginLoader.directories.each(&:run_initializer)

    Redmine::Hook.call_hook :after_plugins_loaded
  end
end

.mirror_assets(name = nil) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/redmine/plugin_loader.rb', line 139

def self.mirror_assets(name=nil)
  if name.present?
    directories.find{|d| d.to_s == File.join(directory, name)}.mirror_assets
  else
    directories.each(&:mirror_assets)
  end
end

.setupObject



114
115
116
117
118
119
120
121
122
# File 'lib/redmine/plugin_loader.rb', line 114

def self.setup
  @plugin_directories = []

  Dir.glob(File.join(directory, '*')).sort.each do |directory|
    next unless File.directory?(directory)

    @plugin_directories << PluginPath.new(directory)
  end
end