Permalink
Browse files

Register the adapter extensions during DataMapper.setup

This means that it's not necessary anymore to require
an explicit adapter before being able to use the
automigration features. Previously it was necessary
to do

  require 'dm-migrations/adapters/dm-mysql-adapter'
  DataMapper.setup(:default, 'mysql://localhost/fu')

whereas all that's need now is

  require 'dm-migrations'
  DataMapper.setup(:default, 'mysql://localhost/fu')

Calling DataMapper.setup will automatically require
the dm-mysql-adapter and register the automigration
extensions
  • Loading branch information...
1 parent 752cbdd commit 2d0c1a9b3b1a36e99d23eef5e3bd3de4f5e9fbdf @snusnu snusnu committed Apr 9, 2010
Showing with 9 additions and 0 deletions.
  1. +1 −0 lib/dm-migrations.rb
  2. +8 −0 lib/dm-migrations/auto_migration.rb
View
1 lib/dm-migrations.rb
@@ -1,2 +1,3 @@
require 'dm-core'
require 'dm-migrations/migration'
+require 'dm-migrations/auto_migration'
View
8 lib/dm-migrations/auto_migration.rb
@@ -187,6 +187,7 @@ module Adapters
# @api private
def const_added(const_name)
+ require auto_migration_extensions(const_name)
if DataMapper::Migrations.const_defined?(const_name)
adapter = const_get(const_name)
adapter.send(:include, DataMapper::Migrations.const_get(const_name))
@@ -195,6 +196,13 @@ def const_added(const_name)
super
end
+ # @api private
+ def auto_migration_extensions(const_name)
+ name = const_name.to_s.gsub('Adapter','').downcase
+ adapter_name = name == 'dataobjects' ? 'do' : name
+ "dm-migrations/adapters/dm-#{adapter_name}-adapter"
+ end
+
end
end

0 comments on commit 2d0c1a9

Please sign in to comment.