<NME> datamapper.nake
<BEF> # encoding: utf-8

# TODO: lazy-loading
require "dm-core"
require "dm-migrations"

  task.define do |environment = "development", options|
    Task[:environment].call(environment)
    Rango.logger.info("[#{Rango.environment}] Migrating databases ...")
    result = DataMapper.auto_migrate!
    Rango.logger.debug("Result: #{result.inspect}")
  end
end
    result = ::DataMapper.auto_migrate!
    Rango.logger.debug("Result: #{result.inspect}")
  end
end

  task.define do |environment = "development", options|
    Task[:environment].call(environment)
    Rango.logger.info("[#{Rango.environment}] Upgrading databases ...")
    result = DataMapper.auto_upgrade!
    Rango.logger.debug("Result: #{result.inspect}")
  end
end
    result = ::DataMapper.auto_upgrade!
    Rango.logger.debug("Result: #{result.inspect}")
  end
end

  task.define do |environment = "development", options|
    Task[:environment].call(environment)
    ObjectSpace.classes.each do |klass|
      if klass.included(DataMapper::Resource)
        puts "#{model_class}: #{model_class.count}"
      end
    end
      if klass.included(::DataMapper::Resource)
        puts "#{model_class}: #{model_class.count}"
      end
    end
  end
end

Task.new("db:migrate") do |task|
  task.hidden = true
  task.define do |*args, options|
    abort "Use #{$0} db:migrate:up version or #{$0} db:migrate:down version"
  end
end

Task.new("db:migrate:load") do |task|
  task.hidden = true
  task.define do |environment, options|
    Task[:environment].call(environment)
    begin
      require "dm-migrations/migration_runner"
    rescue LoadError
      abort "You have to install dm-migrations gem for this!"
    end
    Dir["db/migrations/*.rb"].each do |migration|
      load migration
    end
  end
end

# @since 0.0.2.1
# ./tasks.rb db:migrate:up test --version=10
Task.new("db:migrate:up") do |task|
  task.description = "Migrate up using migrations."
  task.define do |environment = "development", options|
    Task["db:migrate:load"].call(environment)
    migrate_up!(options[:version])
  end
end

# @since 0.0.2.1
# ./tasks.rb db:migrate:down test --version=10
Task.new("db:migrate:down") do |task|
  task.description = "Migrate down using migrations."
  task.define do |environment = "development", options|
    Task["db:migrate:load"].call(environment)
    migrate_down!(options[:version])
  end
end

<MSG> Make DataMapper namespace clear

<DFF> @@ -7,7 +7,7 @@ Task.new("db:automigrate") do |task|
   task.define do |environment = "development", options|
     Task[:environment].call(environment)
     Rango.logger.info("[#{Rango.environment}] Migrating databases ...")
-    result = DataMapper.auto_migrate!
+    result = ::DataMapper.auto_migrate!
     Rango.logger.debug("Result: #{result.inspect}")
   end
 end
@@ -19,7 +19,7 @@ Task.new("db:autoupgrade") do |task|
   task.define do |environment = "development", options|
     Task[:environment].call(environment)
     Rango.logger.info("[#{Rango.environment}] Upgrading databases ...")
-    result = DataMapper.auto_upgrade!
+    result = ::DataMapper.auto_upgrade!
     Rango.logger.debug("Result: #{result.inspect}")
   end
 end
@@ -31,7 +31,7 @@ Task.new("db:report") do |task|
   task.define do |environment = "development", options|
     Task[:environment].call(environment)
     ObjectSpace.classes.each do |klass|
-      if klass.included(DataMapper::Resource)
+      if klass.included(::DataMapper::Resource)
         puts "#{model_class}: #{model_class.count}"
       end
     end

Make DataMapper namespace clear