Skip to content

Commit cbaa1ef

Browse files
committed
Updated rails autoloading to new zeitwerk
See https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#autoloading for more details.
1 parent 156e4b1 commit cbaa1ef

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

bin/rmt-data-import

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require 'json'
2121
require_relative '../config/initializers_cli/disable_deprecation_warnings'
2222
require_relative '../config/initializers_cli/rmt_fast_gettext'
2323
require_relative '../config/initializers_cli/rmt_fast_gettext_cli_locale'
24-
require 'rmt/cli/smt_importer'
2524

2625
no_systems = false
2726
data_dir = nil
@@ -35,8 +34,8 @@ ActiveRecord::Base.establish_connection(db_config)
3534

3635
begin
3736
Time.zone ||= 'UTC'
38-
script = SMTImporter.new(data_dir, no_systems)
37+
script = RMT::CLI::SMTImporter.new(data_dir, no_systems)
3938
script.run ARGV
40-
rescue SMTImporter::ImportException
39+
rescue RMT::CLI::SMTImporter::ImportException
4140
exit 1
4241
end

config/application.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ class Application < Rails::Application
5454

5555
# Initialize configuration defaults for originally generated Rails version.
5656
config.load_defaults 6.0
57-
config.autoloader = :classic
5857

59-
config.autoload_paths << Rails.root.join('lib')
60-
config.autoload_paths << Rails.root.join('app', 'validators')
58+
config.eager_load_paths << Rails.root.join('lib')
59+
config.eager_load_paths << Rails.root.join('app', 'validators')
6160

6261
# Settings in config/environments/* take precedence over those specified here.
6362
# Application configuration can go into files in config/initializers

config/initializers/zeitwerk.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Rails.autoloaders.each do |autoloader|
2+
autoloader.inflector = Zeitwerk::Inflector.new
3+
autoloader.inflector.inflect(
4+
'rmt' => 'RMT',
5+
'cli' => 'CLI',
6+
'suse' => 'SUSE',
7+
'scc' => 'SCC',
8+
'gpg' => 'GPG',
9+
'smt_importer' => 'SMTImporter'
10+
)
11+
end

lib/rmt/cli/smt_importer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'csv'
22
require 'ostruct'
33

4-
class SMTImporter
4+
class RMT::CLI::SMTImporter
55
attr_accessor :data_dir
66
attr_accessor :no_systems
77

spec/lib/rmt/cli/smt_importer_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22
require 'rmt/cli/smt_importer'
33

4-
describe SMTImporter do
4+
describe RMT::CLI::SMTImporter do
55
let(:data_dir) { File.join(Dir.pwd, 'spec/fixtures/files/csv') }
66
let(:no_systems) { false }
77
let(:importer) { described_class.new(data_dir, no_systems) }
@@ -281,7 +281,7 @@
281281

282282
it 'shows the help output when invalid arguments supplied' do
283283
expect do
284-
expect { importer.parse_cli_arguments ['--nope-nope'] }.to raise_exception SMTImporter::ImportException
284+
expect { importer.parse_cli_arguments ['--nope-nope'] }.to raise_exception RMT::CLI::SMTImporter::ImportException
285285
end.to output(<<-OUTPUT.strip_heredoc).to_stdout
286286
Usage: rspec [options]
287287
-d, --data PATH Path to unpacked SMT data tarball
@@ -294,7 +294,7 @@
294294
describe '#check_products_exist' do
295295
it 'warns and exits if no product exists' do
296296
expect do
297-
expect { importer.check_products_exist }.to raise_exception SMTImporter::ImportException
297+
expect { importer.check_products_exist }.to raise_exception RMT::CLI::SMTImporter::ImportException
298298
end.to output(<<-OUTPUT.strip_heredoc).to_stderr
299299
RMT has not been synced to SCC yet. Please run 'rmt-cli sync' before
300300
importing data from SMT.

0 commit comments

Comments
 (0)