diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0515461..9601f3e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: test: strategy: matrix: - ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5' ] + ruby: [ '4.0', '3.4', '3.3', '3.2', '3.1', '3.0', '2.7' ] fail-fast: false runs-on: ubuntu-latest name: ${{ matrix.ruby }} diff --git a/decorators.gemspec b/decorators.gemspec index cf4d34d..518e1a8 100644 --- a/decorators.gemspec +++ b/decorators.gemspec @@ -18,8 +18,8 @@ Gem::Specification.new do |s| readme.md ] - s.add_dependency "railties", ">= 4.0.0", "< 7.2" - s.add_development_dependency "rspec", "~> 3.5", ">= 3.5.0" + s.add_dependency "railties", ">= 4.0.0", "< 9" + s.add_development_dependency "rspec", ">= 3.5.0" s.cert_chain = ["certs/parndt.pem"] if $0.end_with?("gem") && ARGV.include?("build") && ARGV.include?(__FILE__) diff --git a/lib/decorators.rb b/lib/decorators.rb index 29a9916..f139221 100644 --- a/lib/decorators.rb +++ b/lib/decorators.rb @@ -1,6 +1,9 @@ -module Decorators - require "decorators/paths" +# frozen_string_literal: true + +require "decorators/paths" +require "decorators/railtie" +module Decorators class << self def load!(cache_classes) decorators_with_argument_errors = [] @@ -22,9 +25,20 @@ def decorators def register!(*paths_to_register) paths_to_register.flatten.map do |path| paths.register! path + ignore_decorators_path(path) end end + # Tell Zeitwerk to ignore decorator paths (they're loaded manually) + def ignore_decorators_path(path) + return unless defined?(Rails.autoloaders) && Rails.autoloaders.main + + decorators_path = path.join("app", "decorators") + Rails.autoloaders.main.ignore(decorators_path) if decorators_path.exist? + rescue StandardError + # Silently ignore if autoloaders aren't ready yet + end + private def paths @@ -52,5 +66,3 @@ def pattern end end end - -require "decorators/railtie" diff --git a/lib/decorators/paths.rb b/lib/decorators/paths.rb index b906f88..e5fd3c3 100644 --- a/lib/decorators/paths.rb +++ b/lib/decorators/paths.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pathname" module Decorators diff --git a/lib/decorators/railtie.rb b/lib/decorators/railtie.rb index 0cb402a..6820ca2 100644 --- a/lib/decorators/railtie.rb +++ b/lib/decorators/railtie.rb @@ -1,8 +1,14 @@ +# frozen_string_literal: true + require "rails" module Decorators class Railtie < Rails::Railtie config.before_initialize do |app| + # Tell Zeitwerk to ignore app/decorators in the main app + app_decorators = Rails.root.join("app", "decorators") + Rails.autoloaders.main.ignore(app_decorators) if app_decorators.exist? + loader = proc { Decorators.load!(app.config.cache_classes) } if app.config.eager_load