From 54d829c58d11f3785e7a69eb9dd728c77867ca88 Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Wed, 2 Oct 2024 14:41:14 +0200 Subject: [PATCH] Integrate zeitwerk autoload * According to https://community.theforeman.org/t/zeitwerk-merge-imminent/38429 * Requires Foreman 3.13 * Move Exception module for consistent autoloading Co-authored-by: Nadja Heitmann --- .../lib}/foreman_resource_quota/exceptions.rb | 0 lib/foreman_resource_quota/engine.rb | 13 ++++--------- lib/foreman_resource_quota/register.rb | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) rename {lib => app/lib}/foreman_resource_quota/exceptions.rb (100%) diff --git a/lib/foreman_resource_quota/exceptions.rb b/app/lib/foreman_resource_quota/exceptions.rb similarity index 100% rename from lib/foreman_resource_quota/exceptions.rb rename to app/lib/foreman_resource_quota/exceptions.rb diff --git a/lib/foreman_resource_quota/engine.rb b/lib/foreman_resource_quota/engine.rb index 3492aa2..0e96649 100644 --- a/lib/foreman_resource_quota/engine.rb +++ b/lib/foreman_resource_quota/engine.rb @@ -4,13 +4,6 @@ module ForemanResourceQuota class Engine < ::Rails::Engine engine_name 'foreman_resource_quota' - config.autoload_paths += Dir["#{config.root}/app/models/"] - config.autoload_paths += Dir["#{config.root}/app/controllers/"] - config.autoload_paths += Dir["#{config.root}/app/views/"] - config.autoload_paths += Dir["#{config.root}/app/services/foreman_resource_quota/"] - config.autoload_paths += Dir["#{config.root}/app/helpers/foreman_resource_quota/"] - config.autoload_paths += Dir["#{config.root}/lib/"] - # Add db migrations initializer 'foreman_resource_quota.load_app_instance_data' do |app| ForemanResourceQuota::Engine.paths['db/migrate'].existent.each do |path| @@ -34,8 +27,10 @@ class Engine < ::Rails::Engine end # Plugin extensions - initializer 'foreman_resource_quota.register_plugin', before: :finisher_hook do |_app| - require 'foreman_resource_quota/register' + initializer 'foreman_resource_quota.register_plugin', before: :finisher_hook do |app| + app.reloader.to_prepare do + require 'foreman_resource_quota/register' + end end # Include concerns in this config.to_prepare block diff --git a/lib/foreman_resource_quota/register.rb b/lib/foreman_resource_quota/register.rb index 9cae950..63051c3 100644 --- a/lib/foreman_resource_quota/register.rb +++ b/lib/foreman_resource_quota/register.rb @@ -2,7 +2,7 @@ # rubocop: disable Metrics/BlockLength Foreman::Plugin.register :foreman_resource_quota do - requires_foreman '>= 3.5.0' + requires_foreman '>= 3.13' # Apipie apipie_documented_controllers ["#{ForemanResourceQuota::Engine.root}" \ '/app/controllers/foreman_resource_quot/api/v2/*.rb']