diff options
author | kennyj <kennyj@gmail.com> | 2012-06-24 03:06:40 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-06-24 22:18:43 +0900 |
commit | 188d671f148cc2056baede675bed9b61d476c9fe (patch) | |
tree | 0394aced4a075cc3c51e0df90f7e85f9d0fffb49 /activerecord/lib/active_record | |
parent | ebe8a45444fb42b42768fba826f56a498c8b389a (diff) | |
download | rails-188d671f148cc2056baede675bed9b61d476c9fe.tar.gz rails-188d671f148cc2056baede675bed9b61d476c9fe.tar.bz2 rails-188d671f148cc2056baede675bed9b61d476c9fe.zip |
Added a feature to add a database task. e.g. OracleDatabaseTasks
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 999b2ebc85..ff4f41dbeb 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 @@ -75,8 +79,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) |