Skip to content
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

Avoid eager loading ActiveRecord::Base #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions arproxy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'activerecord', '>= 4.2.0'
spec.add_dependency 'activesupport', '>= 4.2.0'

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", ">= 12.3.3"
Expand Down
13 changes: 11 additions & 2 deletions lib/arproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "arproxy/proxy_chain"
require "arproxy/error"
require "arproxy/plugin"
require "active_record"
require "active_support"

module Arproxy
@config = @enabled = nil
Expand All @@ -28,8 +30,15 @@ def enable!
raise Arproxy::Error, "Arproxy should be configured"
end

@proxy_chain = ProxyChain.new @config
@proxy_chain.enable!
if ActiveRecord.autoload? :Base
ActiveSupport.on_load(:active_record, yield: true) do
@proxy_chain = ProxyChain.new @config
@proxy_chain.enable!
end
else
@proxy_chain = ProxyChain.new @config
@proxy_chain.enable!
end

@enabled = true
end
Expand Down
1 change: 0 additions & 1 deletion lib/arproxy/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "active_record"
require "active_record/base"

module Arproxy
class Config
Expand Down