Skip to content

Commit

Permalink
Fixes for Rails v7.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMonkeySteve committed Nov 28, 2024
1 parent ded8627 commit de914bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
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

0 comments on commit de914bf

Please sign in to comment.