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

Fixes for Rails v7.1+ #297

Open
wants to merge 1 commit into
base: master
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
14 changes: 11 additions & 3 deletions lib/no_brainer/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ def eager_autoload(*constants)
end

def eager_load!
super
@_autoloads.keys.map { |c| const_get(c) }
.each { |c| c.eager_load! if c.respond_to?(:eager_load!) }
if NoBrainer.rails71?
if @_eagerloaded_constants
@_eagerloaded_constants.map { |const_name| const_get(const_name) }
.each { |c| c.eager_load! if c.respond_to?(:eager_load!) }
@_eagerloaded_constants = nil
end
else
super
@_autoloads.keys.map { |c| const_get(c) }
.each { |c| c.eager_load! if c.respond_to?(:eager_load!) }
end
end

def autoload_and_include(*constants)
Expand Down
6 changes: 5 additions & 1 deletion lib/no_brainer/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class NoBrainer::Railtie < Rails::Railtie
# Not the cleanest behavior, but if ActiveRecord does it, why not.
unless defined?(ActiveRecord)
console = ActiveSupport::Logger.new(STDERR)
Rails.logger.extend ActiveSupport::Logger.broadcast(console)
if NoBrainer.rails71?
Rails.logger.broadcast_to(console)
else
Rails.logger.extend ActiveSupport::Logger.broadcast(console)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions lib/nobrainer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def rails6?
Gem.loaded_specs['activesupport'].version >= Gem::Version.new('6.0.0')
end

def rails71?
Gem.loaded_specs['activesupport'].version >= Gem::Version.new('7.1.0')
end

def eager_load!
# XXX This forces all the NoBrainer code to be loaded in memory.
# Not to be confused with eager_load() that operates on documents.
Expand Down
Loading