Project

General

Profile

Feature #32938 » alt-0005-Use-zeitwerk.patch

Takashi Kato, 2021-10-27 11:58

View differences:

app/models/custom_field.rb
359 359
    end
360 360
  end
361 361
end
362

  
363
require_dependency 'redmine/field_format'
app/models/enumeration.rb
174 174
    end
175 175
  end
176 176
end
177

  
178
# Force load the subclasses in development mode
179
require_dependency 'time_entry_activity'
180
require_dependency 'document_category'
181
require_dependency 'issue_priority'
app/models/group.rb
127 127
    Watcher.where('user_id = ?', id).delete_all
128 128
  end
129 129
end
130

  
131
require_dependency "group_builtin"
app/models/group_builtin.rb
56 56
    private :create_instance
57 57
  end
58 58
end
59

  
60
require_dependency "group_anonymous"
61
require_dependency "group_non_member"
app/models/principal.rb
217 217
    end
218 218
  end
219 219
end
220

  
221
require_dependency "user"
222
require_dependency "group"
config/application.rb
24 24
    # -- all .rb files in that directory are automatically loaded.
25 25

  
26 26
    # Custom directories with classes and modules you want to be autoloadable.
27
    config.autoload_paths += %W(#{config.root}/lib)
27
    config.autoloader = :zeitwerk
28 28

  
29 29
    # Only load the plugins named here, in the order given (default is alphabetical).
30 30
    # :all can be used as a placeholder for all plugins not explicitly named.
config/initializers/zeitwerk.rb
1
# frozen_string_literal: true
2

  
3
lib = Rails.root.join('lib/redmine')
4
Rails.autoloaders.main.push_dir lib, namespace: Redmine
5

  
6
IGNORE_LIST = [
7
  'wiki_formatting/textile/redcloth3.rb',
8
  'core_ext.rb',
9
  'core_ext'
10
]
11

  
12
class RedmineInflector < Zeitwerk::Inflector
13
  def camelize(basename, abspath)
14
    abspath.match?('redmine\/version.rb\z') ? 'VERSION' : super
15
  end
16
end
17

  
18
Rails.autoloaders.each do |loader|
19
  loader.inflector = RedmineInflector.new
20
  loader.inflector.inflect(
21
    'html' => 'HTML',
22
    'csv' => 'CSV',
23
    'pdf' => 'PDF',
24
    'url' => 'URL',
25
    'pop3' => 'POP3',
26
    'imap' => 'IMAP'
27
  )
28
  IGNORE_LIST.each do |mod|
29
    loader.ignore lib.join(mod)
30
  end
31
end
lib/redmine/plugin_loader.rb
89 89

  
90 90
    def self.create_assets_reloader
91 91
      plugin_assets_dirs = {}
92
      @plugin_directories.each do |dir|
92
      directories.each do |dir|
93 93
        plugin_assets_dirs[dir.assets_dir] = ['*']
94 94
      end
95 95
      ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
......
123 123
        # Add the plugin directories to rails autoload paths
124 124
        engine_cfg = Rails::Engine::Configuration.new(directory.to_s)
125 125
        engine_cfg.paths.add 'lib', eager_load: true
126
        Rails.application.config.eager_load_paths += engine_cfg.eager_load_paths
127
        Rails.application.config.autoload_once_paths += engine_cfg.autoload_once_paths
128
        Rails.application.config.autoload_paths += engine_cfg.autoload_paths
126
        engine_cfg.eager_load_paths.each do |dir|
127
          Rails.autoloaders.main.push_dir dir
128
        end
129 129
      end
130 130
    end
131 131

  
lib/redmine/twofa.rb
55 55

  
56 56
    def self.scan_builtin_schemes
57 57
      Dir[Rails.root.join('lib', 'redmine', 'twofa', '*.rb')].each do |file|
58
        require_dependency file
58
        require file
59 59
      end
60 60
    end
61 61
    private_class_method :scan_builtin_schemes
(16-16/16)