Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Extracted adapter and migration code and specs
The various adapters are now available via the
dm-xxx-adapter repos below the datamapper account
on github.

The auto_migrate!/auto_upgrade! functionality is
now only available in case dm-migrations gets
required. In order to get a datamapper application
up and running along with automigrations,
do the following:

  require 'dm-core' #optional
  require 'dm-migrations'
  DataMapper.setup(:default, 'mysql://localhost/fu')
  # model definitions ...
  DataMapper.auto_migrate!

Failing to require dm-migrations will result in

  undefined method `auto_migrate!'
  for DataMapper:Module (NoMethodError)

From this commit on, dm-core does not provide any
adapters apart from the abstract and in_memory
adapters.

This means that from now on, users will need to
depend on any of the datamapper/dm-xxx-adapter gems
in order to be able to connect to the database of
their choice. If automigration facilities are
desired, it's necessary to also depend on and require
dm-migrations.

Unfortunately, the way dm-core's shared adapter
specs are currently written doesn't lend itself
nicely to the way we want to use them from the
various extracted dm-xxx-adapters. Because we
lazily require the desired adapter only when
DataMapper.setup is called, we cannot require the
shared examples before doing so. This is because
the shared adapter spec relies on the adapter
class to already be known at the time it gets
read in. It relies on that because it checks if
the various adapter methods like :create, :update
etc are supported by the adapter under test. To
workaround this, you can use

  ADAPTER_SUPPORTS=all bundle exec rake spec

to run specs for the various dm-xxx-adapter gems.
A proper fix for this issue would be to write the
shared adapter specs in such a way, that they
evaluate the adapter possibilities only at runtime
and not immediately when the file gets read in.
  • Loading branch information
snusnu committed Apr 9, 2010
1 parent 1e6fbbd commit 98f9311d58357c38beb8c779d12be5f0c62fcb72
Showing 24 changed files with 161 additions and 3,456 deletions.
@@ -17,6 +17,7 @@ tmtags
*.rbc

## PROJECT::GENERAL
*.gem
coverage
rdoc
pkg
44 Gemfile
@@ -1,5 +1,7 @@
source 'http://rubygems.org'

datamapper = 'git://github.com/datamapper'

group :runtime do

# We bundle both AS and extlib while extlib compatibility needs to be kept around.
@@ -40,7 +42,7 @@ group :runtime do
# It was mentioned above that all this is not *strictly* necessary, and this is true.
# Currently dm-core does the following as the first require when checking for AS
#
# require 'active_support/core_ext/object/singleton_class'
# require 'active_support/core_ext/kernel/singleton_class'
#
# Because this method is not present in activesupport <= 3.0.0.beta, dm-core's feature
# detection will actually do the "right thing" and fall back to extlib. However, since
@@ -54,24 +56,42 @@ group :runtime do
#

if ENV['EXTLIB']
gem 'extlib', '~> 0.9.15', :git => 'git://github.com/datamapper/extlib.git'
gem 'extlib', '~> 0.9.15', :git => "#{datamapper}/extlib.git"
else
gem 'activesupport', '~> 3.0.0.beta2', :git => 'git://github.com/rails/rails.git', :require => nil
gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
end

gem 'addressable', '~> 2.1'
end

group :development do
gem 'rake', '~> 0.8.7'
gem 'rspec', '~> 1.3'
gem 'yard', '~> 0.5'
gem 'rcov', '~> 0.9.7'
gem 'jeweler', '~> 1.4'
gem 'data_objects', '~> 0.10.1'
gem 'do_sqlite3', '~> 0.10.1'
gem 'do_mysql', '~> 0.10.1'
gem 'do_postgres', '~> 0.10.1'

gem 'rake', '~> 0.8.7'
gem 'rspec', '~> 1.3'
gem 'yard', '~> 0.5'
gem 'rcov', '~> 0.9.7'
gem 'jeweler', '~> 1.4'

gem 'dm-core', '~> 0.10.3', :path => File.dirname(__FILE__) # Make ourself available to the adapters

gem 'dm-migrations', '~> 0.10.3', :git => "#{datamapper}/dm-migrations.git"

gem 'data_objects', '~> 0.10.2', :git => "#{datamapper}/do.git"
gem 'do_sqlite3', '~> 0.10.2', :git => "#{datamapper}/do.git"
gem 'do_mysql', '~> 0.10.2', :git => "#{datamapper}/do.git"
gem 'do_postgres', '~> 0.10.2', :git => "#{datamapper}/do.git"
gem 'do_oracle', '~> 0.10.2', :git => "#{datamapper}/do.git"
gem 'do_sqlserver', '~> 0.10.2', :git => "#{datamapper}/do.git"

gem 'dm-do-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-do-adapter.git"
gem 'dm-sqlite-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-sqlite-adapter.git"
gem 'dm-postgres-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-postgres-adapter.git"
gem 'dm-mysql-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-mysql-adapter.git"
gem 'dm-oracle-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-oracle-adapter.git"
gem 'dm-sqlserver-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-sqlserver-adapter.git"

gem 'dm-yaml-adapter', '~> 0.10.3', :git => "#{datamapper}/dm-yaml-adapter.git"

end

group :quality do
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dan Kubb"]
s.date = %q{2010-04-06}
s.date = %q{2010-04-09}
s.description = %q{Faster, Better, Simpler.}
s.email = %q{dan.kubb@gmail.com}
s.extra_rdoc_files = [
@@ -29,14 +29,7 @@ Gem::Specification.new do |s|
"lib/dm-core.rb",
"lib/dm-core/adapters.rb",
"lib/dm-core/adapters/abstract_adapter.rb",
"lib/dm-core/adapters/data_objects_adapter.rb",
"lib/dm-core/adapters/in_memory_adapter.rb",
"lib/dm-core/adapters/mysql_adapter.rb",
"lib/dm-core/adapters/oracle_adapter.rb",
"lib/dm-core/adapters/postgres_adapter.rb",
"lib/dm-core/adapters/sqlite3_adapter.rb",
"lib/dm-core/adapters/sqlserver_adapter.rb",
"lib/dm-core/adapters/yaml_adapter.rb",
"lib/dm-core/associations/many_to_many.rb",
"lib/dm-core/associations/many_to_one.rb",
"lib/dm-core/associations/one_to_many.rb",
@@ -53,7 +46,6 @@ Gem::Specification.new do |s|
"lib/dm-core/core_ext/symbol.rb",
"lib/dm-core/core_ext/try_dup.rb",
"lib/dm-core/identity_map.rb",
"lib/dm-core/migrations.rb",
"lib/dm-core/model.rb",
"lib/dm-core/model/descendant_set.rb",
"lib/dm-core/model/hook.rb",
@@ -80,7 +72,6 @@ Gem::Specification.new do |s|
"lib/dm-core/resource/state/persisted.rb",
"lib/dm-core/resource/state/transient.rb",
"lib/dm-core/spec/adapter_shared_spec.rb",
"lib/dm-core/spec/data_objects_adapter_shared_spec.rb",
"lib/dm-core/spec/lib/adapter_helpers.rb",
"lib/dm-core/spec/lib/collection_helpers.rb",
"lib/dm-core/spec/lib/counter_adapter.rb",
@@ -119,7 +110,6 @@ Gem::Specification.new do |s|
"spec/public/associations/one_to_one_spec.rb",
"spec/public/associations/one_to_one_with_boolean_cpk_spec.rb",
"spec/public/collection_spec.rb",
"spec/public/migrations_spec.rb",
"spec/public/model/hook_spec.rb",
"spec/public/model/property_spec.rb",
"spec/public/model/relationship_spec.rb",
@@ -140,12 +130,6 @@ Gem::Specification.new do |s|
"spec/rcov.opts",
"spec/semipublic/adapters/abstract_adapter_spec.rb",
"spec/semipublic/adapters/in_memory_adapter_spec.rb",
"spec/semipublic/adapters/mysql_adapter_spec.rb",
"spec/semipublic/adapters/oracle_adapter_spec.rb",
"spec/semipublic/adapters/postgres_adapter_spec.rb",
"spec/semipublic/adapters/sqlite3_adapter_spec.rb",
"spec/semipublic/adapters/sqlserver_adapter_spec.rb",
"spec/semipublic/adapters/yaml_adapter_spec.rb",
"spec/semipublic/associations/many_to_many_spec.rb",
"spec/semipublic/associations/many_to_one_spec.rb",
"spec/semipublic/associations/one_to_many_spec.rb",
@@ -201,7 +185,6 @@ Gem::Specification.new do |s|
"spec/public/associations/one_to_one_spec.rb",
"spec/public/associations/one_to_one_with_boolean_cpk_spec.rb",
"spec/public/collection_spec.rb",
"spec/public/migrations_spec.rb",
"spec/public/model/hook_spec.rb",
"spec/public/model/property_spec.rb",
"spec/public/model/relationship_spec.rb",
@@ -221,12 +204,6 @@ Gem::Specification.new do |s|
"spec/public/types/discriminator_spec.rb",
"spec/semipublic/adapters/abstract_adapter_spec.rb",
"spec/semipublic/adapters/in_memory_adapter_spec.rb",
"spec/semipublic/adapters/mysql_adapter_spec.rb",
"spec/semipublic/adapters/oracle_adapter_spec.rb",
"spec/semipublic/adapters/postgres_adapter_spec.rb",
"spec/semipublic/adapters/sqlite3_adapter_spec.rb",
"spec/semipublic/adapters/sqlserver_adapter_spec.rb",
"spec/semipublic/adapters/yaml_adapter_spec.rb",
"spec/semipublic/associations/many_to_many_spec.rb",
"spec/semipublic/associations/many_to_one_spec.rb",
"spec/semipublic/associations/one_to_many_spec.rb",
@@ -97,7 +97,6 @@ module ActiveSupport
require 'dm-core/associations/many_to_one'
require 'dm-core/associations/many_to_many'
require 'dm-core/identity_map'
require 'dm-core/migrations' # TODO: move to dm-more
require 'dm-core/property'
require 'dm-core/property_set'
require 'dm-core/query'
@@ -13,6 +13,34 @@ def self.new(repository_name, options)
adapter_class(options.fetch(:adapter)).new(repository_name, options)
end

# The path used to require the in memory adapter
#
# Set this if you want to register your own adapter
# to be used when you specify an 'in_memory' connection
# during
#
# @see DataMapper.setup
#
# @param [String] path
# the path used to require the desired in memory adapter
#
# @api semipublic
def self.in_memory_adapter_path=(path)
@in_memory_adapter_path = path
end

# The path used to require the in memory adapter
#
# @see DataMapper.setup
#
# @return [String]
# the path used to require the desired in memory adapter
#
# @api semipublic
def self.in_memory_adapter_path
@in_memory_adapter_path ||= 'dm-core/adapters/in_memory_adapter'
end

class << self
private

@@ -97,8 +125,9 @@ def normalize_options_string(string)
#
# @api private
def adapter_class(name)
class_name = (ActiveSupport::Inflector.camelize(name) << 'Adapter').to_sym
load_adapter(name) unless const_defined?(class_name)
adapter_name = normalize_adapter_name(name)
class_name = (ActiveSupport::Inflector.camelize(adapter_name) << 'Adapter').to_sym
load_adapter(adapter_name) unless const_defined?(class_name)
const_get(class_name)
end

@@ -112,17 +141,53 @@ def adapter_class(name)
#
# @api private
def load_adapter(name)
name = name.to_sym
require "dm-#{name}-adapter"
rescue LoadError
require in_memory_adapter?(name) ? in_memory_adapter_path : legacy_path(name)
end

# Returns wether or not the given adapter name is considered an in memory adapter
#
# @param [String, Symbol] name
# the name of the adapter
#
# @return [Boolean]
# true if the adapter is considered to be an in memory adapter
#
# @api private
def in_memory_adapter?(name)
name.to_s == 'in_memory'
end

lib = "#{name}_adapter"
file = DataMapper.root / 'lib' / 'dm-core' / 'adapters' / "#{lib}.rb"
# Returns the fallback filename that would be used to require the named adapter
#
# The fallback format is "#{name}_adapter" and will be phased out in favor of
# the properly 'namespaced' "dm-#{name}-adapter" format.
#
# @param [String, Symbol] name
# the name of the adapter to require
#
# @return [String]
# the filename that gets required for the adapter identified by name
#
# @api private
def legacy_path(name)
"#{name}_adapter"
end

if file.file?
require file
else
require lib
end
# Adjust the adapter name to match the name used in the gem providing the adapter
#
# @param [String, Symbol] name
# the name of the adapter
#
# @return [String]
# the normalized adapter name
#
# @api private
def normalize_adapter_name(name)
(original = name.to_s) == 'sqlite3' ? 'sqlite' : original
end

end

extendable do

0 comments on commit 98f9311

Please sign in to comment.