diff --git a/README.md b/README.md index 77efafd..eefb770 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ ActiveRecordDoctor::Rake::Task.new do |task| task.deps = [] # A path to your active_record_doctor configuration file. - task.config_path = ::Rails.root.join(".active_record_doctor") + task.config_path = ::Rails.root.join(".active_record_doctor.rb") # A Proc called right before running detectors that should ensure your Active # Record models are preloaded and a database connection is ready. @@ -111,7 +111,7 @@ If you want to use the default configuration then you don't have to do anything. Just run `active_record_doctor` in your project directory. If you want to customize the tool you should create a file named -`.active_record_doctor` in your project root directory with content like: +`.active_record_doctor.rb` in your project root directory with content like: ```ruby ActiveRecordDoctor.configure do diff --git a/lib/active_record_doctor/rake/task.rb b/lib/active_record_doctor/rake/task.rb index 57586a4..43c2f69 100644 --- a/lib/active_record_doctor/rake/task.rb +++ b/lib/active_record_doctor/rake/task.rb @@ -68,9 +68,41 @@ def runner end def config - @config ||= begin - path = config_path && File.exist?(config_path) ? config_path : nil - ActiveRecordDoctor.load_config_with_defaults(path) + @config ||= + ActiveRecordDoctor.load_config_with_defaults(effective_config_path) + end + + def effective_config_path + if config_path.nil? + # No explicit config_path was set, so we're trying to use defaults. + legacy_default_path = Rails.root.join(".active_record_doctor") + new_default_path = Rails.root.join(".active_record_doctor.rb") + + # First, if the legacy file exists we'll use it but show a warning. + if legacy_default_path.exist? + warn(<<~WARN.squish) + DEPRECATION WARNING: active_record_doctor is using the default + configuration file located in #{legacy_default_path.basename}. However, + that default will change to #{new_default_path.basename} in the future. + + In order to avoid errors, please rename the file from + #{legacy_default_path.basename} to #{new_default_path.basename}. + WARN + + return legacy_default_path + end + + # Second, if the legacy file does NOT exist, but the new one does then + # we'll use that. + if new_default_path.exist? + return new_default_path + end + + # Otherwise, there's no configuration file in use. + nil + else + # If an explicit configuration file was set then we use it as is. + config_path end end diff --git a/lib/tasks/active_record_doctor.rake b/lib/tasks/active_record_doctor.rake index c6925ab..e96cc7d 100644 --- a/lib/tasks/active_record_doctor.rake +++ b/lib/tasks/active_record_doctor.rake @@ -19,6 +19,5 @@ ActiveRecordDoctor::Rake::Task.new do |task| # This file is imported when active_record_doctor is being used as part of a # Rails app so it's the right place for all Rails-specific settings. task.deps = [:environment] - task.config_path = Rails.root.join(".active_record_doctor") task.setup = -> { Rails.application.eager_load! } end diff --git a/test/setup.rb b/test/setup.rb index c6c1550..4ede3e8 100644 --- a/test/setup.rb +++ b/test/setup.rb @@ -127,7 +127,7 @@ def config_file(content) @previous_dir = Dir.pwd directory = Dir.mktmpdir("active_record_doctor") - @config_path = File.join(directory, ".active_record_doctor") + @config_path = File.join(directory, ".active_record_doctor.rb") File.write(@config_path, content) Dir.chdir(directory)