]> source.dussan.org Git - redmine.git/commitdiff
Switch to zeitwerk autoloader (#29914, #32938).
authorMarius Balteanu <marius.balteanu@zitec.com>
Wed, 17 Nov 2021 20:55:08 +0000 (20:55 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Wed, 17 Nov 2021 20:55:08 +0000 (20:55 +0000)
Patch by Takashi Kato.

git-svn-id: http://svn.redmine.org/redmine/trunk@21287 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_field.rb
app/models/enumeration.rb
app/models/group.rb
app/models/group_builtin.rb
app/models/principal.rb
config/application.rb
config/initializers/zeitwerk.rb [new file with mode: 0644]
lib/redmine/plugin_loader.rb
lib/redmine/twofa.rb

index 9787b2ee4d5a8cf6d8898284f8fc86b1515336db..b81dae233e44c715448729edf0862b5ef29c0397 100644 (file)
@@ -359,5 +359,3 @@ class CustomField < ActiveRecord::Base
     end
   end
 end
-
-require_dependency 'redmine/field_format'
index 53360e5ff836b8502df034f5ace836c259220fc9..5f0e023ed95622e70657a2ddaf3762369c196bed 100644 (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'
index a676816ecf61501474a9d2885df4b19345bb7a82..881dfb14965e027f15d58d5ea285a981000fa8c0 100644 (file)
@@ -127,5 +127,3 @@ class Group < Principal
     Watcher.where('user_id = ?', id).delete_all
   end
 end
-
-require_dependency "group_builtin"
index 0c29d50da695313d6294957d951a50f06ae67340..5d2eccde5d8cbe6ea07ed3910539591e4824f2e9 100644 (file)
@@ -56,6 +56,3 @@ class GroupBuiltin < Group
     private :create_instance
   end
 end
-
-require_dependency "group_anonymous"
-require_dependency "group_non_member"
index 495d55669ed1baceeb68824a1d4f9f111a299553..7004e7d93121f9c9d101c2170feef8cd3a5dd601 100644 (file)
@@ -217,6 +217,3 @@ class Principal < ActiveRecord::Base
     end
   end
 end
-
-require_dependency "user"
-require_dependency "group"
index fc6e6a33f4b2f94d3b41dbba071b306f6efc8c3a..e74fcbf6783bed21414056db30478c73755ba3b4 100644 (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.
diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb
new file mode 100644 (file)
index 0000000..f5630b3
--- /dev/null
@@ -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
index 3009560e2f1c802302d3663016ff76f93ece3812..43219a116204d53674dee24e98be258ce26ba62f 100644 (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
 
index 612cdec9925adf2d95f4c347fe2cb28f62db755f..cfa0ea422e4375ee5edf571781ebe2bec5a641eb 100644 (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