-
Notifications
You must be signed in to change notification settings - Fork 246
feat: migrate from ActiveSupport::Autoload to Zeitwerk #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,50 +1,22 @@ | ||||||||||
# frozen_string_literal: true | ||||||||||
|
||||||||||
require 'active_record' | ||||||||||
require 'zeitwerk' | ||||||||||
|
||||||||||
module ClosureTree | ||||||||||
extend ActiveSupport::Autoload | ||||||||||
|
||||||||||
autoload :HasClosureTree | ||||||||||
autoload :HasClosureTreeRoot | ||||||||||
autoload :Support | ||||||||||
autoload :HierarchyMaintenance | ||||||||||
autoload :Model | ||||||||||
autoload :Finders | ||||||||||
autoload :HashTree | ||||||||||
autoload :Digraphs | ||||||||||
autoload :DeterministicOrdering | ||||||||||
autoload :NumericDeterministicOrdering | ||||||||||
autoload :Configuration | ||||||||||
autoload :AdapterSupport | ||||||||||
loader = Zeitwerk::Loader.for_gem | ||||||||||
loader.ignore("#{__dir__}/generators") | ||||||||||
loader.setup | ||||||||||
|
||||||||||
module ClosureTree | ||||||||||
def self.configure | ||||||||||
yield configuration | ||||||||||
ActiveSupport::Deprecation.new.warn( | ||||||||||
'ClosureTree.configure is deprecated and will be removed in a future version. ' \ | ||||||||||
'Configuration is no longer needed.' | ||||||||||
) | ||||||||||
yield if block_given? | ||||||||||
end | ||||||||||
|
||||||||||
def self.configuration | ||||||||||
@configuration ||= Configuration.new | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
ActiveSupport.on_load :active_record do | ||||||||||
ActiveRecord::Base.extend ClosureTree::HasClosureTree | ||||||||||
ActiveRecord::Base.extend ClosureTree::HasClosureTreeRoot | ||||||||||
end | ||||||||||
|
||||||||||
# Adapter injection for different database types | ||||||||||
ActiveSupport.on_load :active_record_postgresqladapter do | ||||||||||
prepend ClosureTree::AdapterSupport | ||||||||||
end | ||||||||||
|
||||||||||
ActiveSupport.on_load :active_record_mysql2adapter do | ||||||||||
prepend ClosureTree::AdapterSupport | ||||||||||
end | ||||||||||
|
||||||||||
ActiveSupport.on_load :active_record_trilogyadapter do | ||||||||||
prepend ClosureTree::AdapterSupport | ||||||||||
end | ||||||||||
|
||||||||||
ActiveSupport.on_load :active_record_sqlite3adapter do | ||||||||||
prepend ClosureTree::AdapterSupport | ||||||||||
ActiveSupport.on_load(:active_record) do | ||||||||||
extend ClosureTree::HasClosureTree, ClosureTree::HasClosureTreeRoot | ||||||||||
end | ||||||||||
Comment on lines
+20
to
22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The context should be
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new ActiveSupport::Deprecation instance for each call is inefficient. Consider using ActiveSupport::Deprecation.warn directly or creating a shared deprecation instance.
Copilot uses AI. Check for mistakes.