-
Notifications
You must be signed in to change notification settings - Fork 898
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
De-couple DescendantLoader from Rails #15460
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 |
---|---|---|
|
@@ -45,6 +45,10 @@ | |
# When Active Record calls `Bbb.descendants` to construct the `type` | ||
# condition, `Ccc` is automatically loaded. | ||
# | ||
|
||
require "active_record" | ||
require_relative "../manageiq" | ||
|
||
class DescendantLoader | ||
CACHE_VERSION = 2 | ||
|
||
|
@@ -63,6 +67,13 @@ def self.status(io = $stdout) | |
io.puts | ||
end | ||
|
||
def self.setup | ||
return if @setup_complete | ||
ActiveRecord::Base.singleton_class.send(:prepend, DescendantLoader::ArDescendantsWithLoader) | ||
ActiveSupport::Dependencies.send(:prepend, DescendantLoader::AsDependenciesClearWithLoader) | ||
@setup_complete = true | ||
end | ||
|
||
# Extract class definitions (namely: a list of which scopes it might | ||
# be defined in [depending on runtime details], the name of the class, | ||
# and the name of its superclass), given a path to a ruby script file. | ||
|
@@ -159,7 +170,7 @@ def name_combinations(names) | |
# RubyParser is slow, so wrap it in a simple mtime-based cache. | ||
module Cache | ||
def cache_path | ||
Rails.root.join('tmp/cache/sti_loader.yml') | ||
ManageIQ.root.join('tmp/cache/sti_loader.yml') | ||
end | ||
|
||
def load_cache | ||
|
@@ -199,7 +210,7 @@ def classes_in(filename) | |
|
||
module Mapper | ||
def descendants_paths | ||
@descendants_paths ||= [Rails.root.join("app/models")] | ||
@descendants_paths ||= [ManageIQ.root.join("app/models")] | ||
end | ||
|
||
def class_inheritance_relationships | ||
|
@@ -266,9 +277,7 @@ def clear | |
end | ||
end | ||
|
||
ActiveRecord::Base.singleton_class.send(:prepend, DescendantLoader::ArDescendantsWithLoader) | ||
ActiveSupport::Dependencies.send(:prepend, DescendantLoader::AsDependenciesClearWithLoader) | ||
ActsAsArModel.singleton_class.send(:prepend, DescendantLoader::ArDescendantsWithLoader) | ||
DescendantLoader.setup | ||
|
||
at_exit do | ||
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. Technically, this should be part of the setup as well. (The 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. Maybe address this comment? 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. Agreed. Will do. Should have confirmed that I intended to do that originally. Will look into doing this tomorrow. |
||
DescendantLoader.instance.save_cache! | ||
|
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.
Remove the .rb
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.
I'm concerned that this breaks Rails autoloading, but that concern is probably minor/unwarranted.
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.
I will look into this.
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.
Following the precedent from my other recent comment:
.rb
(for some reason I thought it was required... or helped in some way, but nope)