diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-07 05:58:01 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-07 05:58:01 -0700 |
commit | 84b97813f687d1ed4b283e4f579ef6965988a2f6 (patch) | |
tree | f7a0dcc58ec196f65eda04e29a72cb51e0bb5d31 /activerecord/lib/active_record | |
parent | ea7b48b0748a7a9c87ec9409039e3e436bbe51fc (diff) | |
parent | 188d671f148cc2056baede675bed9b61d476c9fe (diff) | |
download | rails-84b97813f687d1ed4b283e4f579ef6965988a2f6.tar.gz rails-84b97813f687d1ed4b283e4f579ef6965988a2f6.tar.bz2 rails-84b97813f687d1ed4b283e4f579ef6965988a2f6.zip |
Merge pull request #6838 from kennyj/added_registration_task
Allow to register database tasks from different adapters
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index f1241502f5..fb3dfc2730 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -3,13 +3,17 @@ module ActiveRecord module DatabaseTasks # :nodoc: extend self - TASKS_PATTERNS = { - /mysql/ => ActiveRecord::Tasks::MySQLDatabaseTasks, - /postgresql/ => ActiveRecord::Tasks::PostgreSQLDatabaseTasks, - /sqlite/ => ActiveRecord::Tasks::SQLiteDatabaseTasks - } LOCAL_HOSTS = ['127.0.0.1', 'localhost'] + def register_task(pattern, task) + @tasks ||= {} + @tasks[pattern] = task + end + + register_task(/mysql/, ActiveRecord::Tasks::MySQLDatabaseTasks) + register_task(/postgresql/, ActiveRecord::Tasks::PostgreSQLDatabaseTasks) + register_task(/sqlite/, ActiveRecord::Tasks::SQLiteDatabaseTasks) + def create(*arguments) configuration = arguments.first class_for_adapter(configuration['adapter']).new(*arguments).create @@ -84,8 +88,8 @@ module ActiveRecord private def class_for_adapter(adapter) - key = TASKS_PATTERNS.keys.detect { |pattern| adapter[pattern] } - TASKS_PATTERNS[key] + key = @tasks.keys.detect { |pattern| adapter[pattern] } + @tasks[key] end def each_current_configuration(environment) |