Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions decorators.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
20 changes: 16 additions & 4 deletions lib/decorators.rb
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -52,5 +66,3 @@ def pattern
end
end
end

require "decorators/railtie"
2 changes: 2 additions & 0 deletions lib/decorators/paths.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "pathname"

module Decorators
Expand Down
6 changes: 6 additions & 0 deletions lib/decorators/railtie.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading