diff options
author | Akira Matsuda <ronnie@dio.jp> | 2017-05-11 17:40:41 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2017-05-11 18:01:26 +0900 |
commit | f73b845610931ddf03c756d804982776a3cc69a4 (patch) | |
tree | 840536837bb62f17ebb4b3d0db067ae4ea0315b4 /activerecord/lib/active_record | |
parent | 22bfc5f4847f96549688314d9ee4c01d07d4589b (diff) | |
download | rails-f73b845610931ddf03c756d804982776a3cc69a4.tar.gz rails-f73b845610931ddf03c756d804982776a3cc69a4.tar.bz2 rails-f73b845610931ddf03c756d804982776a3cc69a4.zip |
Defer loading each DB Tasks class from AR DatabaseTasks
Because we don't need to load tasks for DBs that we don't use for the current app.
Also, these Tasks classes load AR::Base in their class level, and so immediately kick :active_record on_load hooks.
This used to happen when we were loading tasks, not when we run a task.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 45110a79cd..c53dee43d7 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -71,9 +71,9 @@ module ActiveRecord @tasks[pattern] = task end - register_task(/mysql/, ActiveRecord::Tasks::MySQLDatabaseTasks) - register_task(/postgresql/, ActiveRecord::Tasks::PostgreSQLDatabaseTasks) - register_task(/sqlite/, ActiveRecord::Tasks::SQLiteDatabaseTasks) + register_task(/mysql/, 'ActiveRecord::Tasks::MySQLDatabaseTasks') + register_task(/postgresql/, 'ActiveRecord::Tasks::PostgreSQLDatabaseTasks') + register_task(/sqlite/, 'ActiveRecord::Tasks::SQLiteDatabaseTasks') def db_dir @db_dir ||= Rails.application.config.paths["db"].first @@ -288,11 +288,11 @@ module ActiveRecord private def class_for_adapter(adapter) - key = @tasks.keys.detect { |pattern| adapter[pattern] } - unless key + _key, task = @tasks.each_pair.detect { |pattern, _task| adapter[pattern] } + unless task raise DatabaseNotSupported, "Rake tasks not supported by '#{adapter}' adapter" end - @tasks[key] + task.is_a?(String) ? task.constantize : task end def each_current_configuration(environment) |