@@ -55,15 +55,35 @@ class ActiveSupportOnLoad < Base
5555 'ActiveSupport::TestCase' => 'active_support_test_case'
5656 } . freeze
5757
58+ RAILS_5_2_LOAD_HOOKS = {
59+ 'ActiveRecord::ConnectionAdapters::SQLite3Adapter' => 'active_record_sqlite3adapter'
60+ } . freeze
61+
62+ RAILS_7_1_LOAD_HOOKS = {
63+ 'ActiveRecord::TestFixtures' => 'active_record_fixtures' ,
64+ 'ActiveModel::Model' => 'active_model' ,
65+ 'ActionText::EncryptedRichText' => 'action_text_encrypted_rich_text' ,
66+ 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'active_record_postgresqladapter' ,
67+ 'ActiveRecord::ConnectionAdapters::Mysql2Adapter' => 'active_record_mysql2adapter' ,
68+ 'ActiveRecord::ConnectionAdapters::TrilogyAdapter' => 'active_record_trilogyadapter'
69+ } . freeze
70+
5871 def on_send ( node )
5972 receiver , method , arguments = *node # rubocop:disable InternalAffairs/NodeDestructuring
60- return unless arguments && ( hook = LOAD_HOOKS [ receiver &.const_name ] )
73+ return unless arguments && ( hook = hook_for_const ( receiver &.const_name ) )
6174
6275 preferred = "ActiveSupport.on_load(:#{ hook } ) { #{ method } #{ arguments . source } }"
6376 add_offense ( node , message : format ( MSG , prefer : preferred , current : node . source ) ) do |corrector |
6477 corrector . replace ( node , preferred )
6578 end
6679 end
80+
81+ def hook_for_const ( const_name )
82+ hook = LOAD_HOOKS [ const_name ]
83+ hook ||= RAILS_5_2_LOAD_HOOKS [ const_name ] if target_rails_version >= 5.2
84+ hook ||= RAILS_7_1_LOAD_HOOKS [ const_name ] if target_rails_version >= 7.1
85+ hook
86+ end
6787 end
6888 end
6989 end
0 commit comments