1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-03 23:53:23 +00:00

Switch to zeitwerk autoloader (#29914, #32938).

Patch by Takashi Kato.

git-svn-id: http://svn.redmine.org/redmine/trunk@21287 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu 2021-11-17 20:55:08 +00:00
parent e82b0a77e3
commit a914cf4c40
9 changed files with 37 additions and 21 deletions

View File

@ -359,5 +359,3 @@ class CustomField < ActiveRecord::Base
end
end
end
require_dependency 'redmine/field_format'

View File

@ -174,8 +174,3 @@ class Enumeration < ActiveRecord::Base
end
end
end
# Force load the subclasses in development mode
require_dependency 'time_entry_activity'
require_dependency 'document_category'
require_dependency 'issue_priority'

View File

@ -127,5 +127,3 @@ class Group < Principal
Watcher.where('user_id = ?', id).delete_all
end
end
require_dependency "group_builtin"

View File

@ -56,6 +56,3 @@ class GroupBuiltin < Group
private :create_instance
end
end
require_dependency "group_anonymous"
require_dependency "group_non_member"

View File

@ -217,6 +217,3 @@ class Principal < ActiveRecord::Base
end
end
end
require_dependency "user"
require_dependency "group"

View File

@ -24,7 +24,7 @@ module RedmineApp
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/lib)
config.autoloader = :zeitwerk
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
lib = Rails.root.join('lib/redmine')
Rails.autoloaders.main.push_dir lib, namespace: Redmine
IGNORE_LIST = [
'wiki_formatting/textile/redcloth3.rb',
'core_ext.rb',
'core_ext'
]
class RedmineInflector < Zeitwerk::Inflector
def camelize(basename, abspath)
abspath.match?('redmine\/version.rb\z') ? 'VERSION' : super
end
end
Rails.autoloaders.each do |loader|
loader.inflector = RedmineInflector.new
loader.inflector.inflect(
'html' => 'HTML',
'csv' => 'CSV',
'pdf' => 'PDF',
'url' => 'URL',
'pop3' => 'POP3',
'imap' => 'IMAP'
)
IGNORE_LIST.each do |mod|
loader.ignore lib.join(mod)
end
end

View File

@ -89,7 +89,7 @@ module Redmine
def self.create_assets_reloader
plugin_assets_dirs = {}
@plugin_directories.each do |dir|
directories.each do |dir|
plugin_assets_dirs[dir.assets_dir] = ['*']
end
ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
@ -123,9 +123,9 @@ module Redmine
# 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
Rails.application.config.eager_load_paths += engine_cfg.eager_load_paths
Rails.application.config.autoload_once_paths += engine_cfg.autoload_once_paths
Rails.application.config.autoload_paths += engine_cfg.autoload_paths
engine_cfg.eager_load_paths.each do |dir|
Rails.autoloaders.main.push_dir dir
end
end
end

View File

@ -55,7 +55,7 @@ module Redmine
def self.scan_builtin_schemes
Dir[Rails.root.join('lib', 'redmine', 'twofa', '*.rb')].each do |file|
require_dependency file
require file
end
end
private_class_method :scan_builtin_schemes