Permalink
Browse files

Merge branch 'master' of git@github.com:sam/dm-core

  • Loading branch information...
2 parents 47c6c6c + cef2804 commit 1e78ba8f55b3570d0831ee611b952738fb8d0a67 @david david committed Apr 10, 2008
Showing with 1,108 additions and 987 deletions.
  1. +19 −15 .autotest
  2. +17 −14 Rakefile
  3. +5 −5 environment.rb
  4. +52 −3 lib/data_mapper.rb
  5. +21 −21 lib/data_mapper/adapters/abstract_adapter.rb
  6. +71 −70 lib/data_mapper/adapters/data_objects_adapter.rb
  7. +1 −1 lib/data_mapper/adapters/mysql_adapter.rb
  8. +4 −4 lib/data_mapper/adapters/postgres_adapter.rb
  9. +21 −15 lib/data_mapper/associations.rb
  10. +9 −5 lib/data_mapper/associations/many_to_many.rb
  11. +32 −22 lib/data_mapper/associations/many_to_one.rb
  12. +47 −32 lib/data_mapper/associations/one_to_many.rb
  13. +15 −9 lib/data_mapper/associations/one_to_one.rb
  14. +32 −23 lib/data_mapper/associations/parent_to_child_association.rb
  15. +41 −32 lib/data_mapper/associations/relationship.rb
  16. +6 −5 lib/data_mapper/auto_migrations.rb
  17. +6 −7 lib/data_mapper/dependency_queue.rb
  18. +14 −14 lib/data_mapper/identity_map.rb
  19. +3 −1 lib/data_mapper/is/tree.rb
  20. +28 −30 lib/data_mapper/loaded_set.rb
  21. +2 −2 lib/data_mapper/logger.rb
  22. +63 −64 lib/data_mapper/property.rb
  23. +6 −4 lib/data_mapper/property_set.rb
  24. +57 −42 lib/data_mapper/query.rb
  25. +31 −97 lib/data_mapper/repository.rb
  26. +47 −47 lib/data_mapper/resource.rb
  27. +1 −7 lib/data_mapper/scope.rb
  28. +10 −1 lib/data_mapper/support/kernel.rb
  29. +6 −8 lib/data_mapper/type.rb
  30. +28 −0 lib/data_mapper/types/csv.rb
  31. +31 −0 lib/data_mapper/types/yaml.rb
  32. +1 −1 spec/integration/association_spec.rb
  33. +3 −3 spec/integration/mysql_adapter_spec.rb
  34. +1 −1 spec/integration/postgres_adapter_spec.rb
  35. +12 −12 spec/integration/property_spec.rb
  36. +17 −17 spec/integration/query_spec.rb
  37. +2 −2 spec/integration/repository_spec.rb
  38. +2 −2 spec/integration/sqlite3_adapter_spec.rb
  39. +30 −46 spec/integration/type_spec.rb
  40. +4 −6 spec/{ → lib}/mock_adapter.rb
  41. +1 −1 spec/spec.opts
  42. +7 −6 spec/spec_helper.rb
  43. +10 −10 spec/{ → unit}/adapters/abstract_adapter_spec.rb
  44. +0 −1 spec/{ → unit/adapters}/adapter_shared_spec.rb
  45. +39 −39 spec/{ → unit}/adapters/data_objects_adapter_spec.rb
  46. +6 −6 spec/{ → unit}/associations/many_to_many_spec.rb
  47. +2 −4 spec/{ → unit}/associations/many_to_one_spec.rb
  48. +3 −3 spec/{ → unit}/associations/one_to_many_spec.rb
  49. +3 −2 spec/{ → unit}/associations/one_to_one_spec.rb
  50. +32 −28 spec/{ → unit}/associations/relationship_spec.rb
  51. +23 −24 spec/{ → unit}/cli_spec.rb
  52. +9 −9 spec/{ → unit}/dependency_spec.rb
  53. +40 −37 spec/{ → unit}/hook_spec.rb
  54. +38 −39 spec/{ → unit}/identity_map_spec.rb
  55. +4 −4 spec/{ → unit}/loaded_set_spec.rb
  56. +2 −2 spec/{ → unit}/naming_conventions_spec.rb
  57. +1 −1 spec/{ → unit}/property_set_spec.rb
  58. +3 −3 spec/{ → unit}/property_spec.rb
  59. +1 −1 spec/{ → unit}/query_spec.rb
  60. +8 −8 spec/{ → unit}/repository_spec.rb
  61. +10 −5 spec/{ → unit}/resource_spec.rb
  62. +1 −1 spec/{ → unit}/scope_spec.rb
  63. +38 −36 spec/{ → unit}/support/aliasinghash_spec.rb
  64. +1 −1 spec/{ → unit}/support/blank_spec.rb
  65. +1 −1 spec/{ → unit/support}/inflection_spec.rb
  66. +4 −4 spec/{ → unit}/support/object_spec.rb
  67. +2 −2 spec/{ → unit}/support/string_spec.rb
  68. +6 −6 spec/{ → unit}/support/struct_spec.rb
  69. +15 −13 spec/{ → unit}/type_spec.rb
View
@@ -1,22 +1,26 @@
Autotest.add_hook :initialize do |at|
- ignore = %w{.git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README}
+ ignore = %w[ .git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README ]
+
unless ENV['AUTOTEST'] == 'integration'
ignore << 'spec/integration'
end
-
- ignore.each do |exception|
+
+ ignore.each do |exception|
at.add_exception(exception)
end
-
+
at.clear_mappings
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^lib/data_mapper/(.*)\.rb$%) { |_, m|
- ["spec/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^spec/spec_helper.rb$%) {
- at.files_matching %r%^spec/.*_spec\.rb$%
- }
-
-end
+
+ at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
+ filename
+ end
+
+ at.add_mapping(%r{^lib/data_mapper/(.+)\.rb$}) do |_,match|
+ [ "spec/unit/#{match[1]}_spec.rb" ] +
+ at.files_matching(%r{^spec/integration/.+_spec\.rb$})
+ end
+
+ at.add_mapping(%r{^spec/spec_helper\.rb$}) do
+ at.files_matching(%r{^spec/.+_spec\.rb$})
+ end
+end
View
@@ -22,17 +22,20 @@ namespace :dm do
task :environment do
require 'environment'
end
-
+
desc "Run specifications"
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = ["--format", "specdoc", "--colour"]
t.spec_files = Pathname.glob(ENV['FILES'] || __DIR__ + 'spec/**/*_spec.rb')
unless ENV['NO_RCOV']
t.rcov = true
- t.rcov_opts = ['--exclude', 'spec,environment.rb']
+ t.rcov_opts << '--exclude' << 'spec,environment.rb'
+ t.rcov_opts << '--text-summary'
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
+ t.rcov_opts << '--only-uncovered'
end
end
-
+
desc "Run comparison with ActiveRecord"
task :perf do
load __DIR__ + 'script/performance.rb'
@@ -46,7 +49,7 @@ end
PACKAGE_VERSION = '0.9.0'
-PACKAGE_FILES = Pathname.glob([
+PACKAGE_FILES = [
'README',
'FAQ',
'QUICKLINKS',
@@ -57,7 +60,7 @@ PACKAGE_FILES = Pathname.glob([
'spec/**/*.{rb,yaml}',
'tasks/**/*',
'plugins/**/*'
-]).reject { |path| path =~ /(\/db|Makefile|\.bundle|\.log|\.o)\z/ }
+].collect { |pattern| Pathname.glob(pattern) }.flatten.reject { |path| path.to_s =~ /(\/db|Makefile|\.bundle|\.log|\.o)\z/ }
DOCUMENTED_FILES = PACKAGE_FILES.reject do |path|
path.directory? || path.to_s.match(/(?:^spec|\/spec|\/swig\_)/)
@@ -78,19 +81,19 @@ rd = Rake::RDocTask.new do |rdoc|
end
gem_spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = PROJECT
+ s.platform = Gem::Platform::RUBY
+ s.name = PROJECT
s.summary = "An Object/Relational Mapper for Ruby"
s.description = "Faster, Better, Simpler."
- s.version = PACKAGE_VERSION
-
+ s.version = PACKAGE_VERSION
+
s.authors = "Sam Smoot"
s.email = "ssmoot@gmail.com"
- s.rubyforge_project = PROJECT
- s.homepage = "http://datamapper.org"
-
+ s.rubyforge_project = PROJECT
+ s.homepage = "http://datamapper.org"
+
s.files = PACKAGE_FILES.map { |f| f.to_s }
-
+
s.require_path = "lib"
s.requirements << "none"
s.executables = ["dm"]
@@ -101,7 +104,7 @@ gem_spec = Gem::Specification.new do |s|
s.add_dependency("data_objects", ">=0.9.0")
s.add_dependency("english")
- s.has_rdoc = true
+ s.has_rdoc = true
s.rdoc_options << "--line-numbers" << "--inline-source" << "--main" << "README"
s.extra_rdoc_files = DOCUMENTED_FILES.map { |f| f.to_s }
end
View
@@ -2,26 +2,26 @@
# Require the DataMapper, and a Mock Adapter.
require 'pathname'
require Pathname(__FILE__).dirname.expand_path + 'lib/data_mapper'
- require __DIR__ + 'spec/mock_adapter'
+ require __DIR__ + 'spec/lib/mock_adapter'
require 'fileutils'
adapter = ENV["ADAPTER"] || "sqlite3"
-
+
repository_uri = URI.parse case ENV["ADAPTER"]
when 'mysql' then "mysql://localhost/data_mapper_1"
when 'postgres' then "postgres://localhost/data_mapper_1"
else "sqlite3://#{Dir.getwd}/data_mapper_1.db"
end
DataMapper.setup(:default, "mock://localhost")
-
+
# Determine log path.
ENV['_'] =~ /(\w+)/
log_path = __DIR__ + "log/#{$1 == 'opt' ? 'spec' : $1}.log"
-
+
FileUtils::mkdir_p(File.dirname(log_path))
# FileUtils::rm(log_path) if File.exists?(log_path)
-
+
DataMapper::Logger.new(log_path, 0)
at_exit { DataMapper.logger.close }
View
@@ -5,7 +5,7 @@
# * Sets the applications root and environment for compatibility with rails or merb
# * Checks for the database.yml and loads it if it exists
# * Sets up the database using the config from the yaml file or from the environment
-#
+#
# Require the basics...
require 'pathname'
@@ -30,11 +30,60 @@
require __DIR__ + 'data_mapper/support/inflection'
require __DIR__ + 'data_mapper/support/struct'
+require __DIR__ + 'data_mapper/logger'
require __DIR__ + 'data_mapper/dependency_queue'
+require __DIR__ + 'data_mapper/repository'
require __DIR__ + 'data_mapper/resource'
+require __DIR__ + 'data_mapper/query'
require __DIR__ + 'data_mapper/adapters/abstract_adapter'
require __DIR__ + 'data_mapper/cli'
-require __DIR__ + 'data_mapper/scope'
-require __DIR__ + 'data_mapper/query'
+module DataMapper
+ def self.setup(name, uri, options = {})
+ uri = String === uri ? URI.parse(uri) : uri
+
+ raise ArgumentError, "+name+ must be a Symbol, but was #{name.class}", caller unless Symbol === name
+ raise ArgumentError, "+uri+ must be a URI or String, but was #{uri.class}", caller unless URI === uri
+ unless Adapters::const_defined?(DataMapper::Inflection.classify(uri.scheme) + 'Adapter')
+ begin
+ require __DIR__ + "data_mapper/adapters/#{DataMapper::Inflection.underscore(uri.scheme)}_adapter"
+ rescue LoadError
+ require "#{DataMapper::Inflection.underscore(uri.scheme)}_adapter"
+ end
+ end
+
+ adapter = Adapters::const_get(DataMapper::Inflection.classify(uri.scheme) + 'Adapter').new(name, uri)
+
+ Repository.adapters[name] = adapter
+ end
+
+ # ===Block Syntax:
+ # Pushes the named repository onto the context-stack,
+ # yields a new session, and pops the context-stack.
+ #
+ # results = DataMapper.repository(:second_database) do |current_context|
+ # ...
+ # end
+ #
+ # ===Non-Block Syntax:
+ # Returns the current session, or if there is none,
+ # a new Session.
+ #
+ # current_repository = DataMapper.repository
+ def self.repository(name = :default) # :yields: current_context
+ unless block_given?
+ begin
+ Repository.context.last || Repository.new(name)
+ #rescue NoMethodError
+ # raise RepositoryNotSetupError, "#{name.inspect} repository not set up."
+ end
+ else
+ begin
+ return yield(Repository.context.push(Repository.new(name)))
+ ensure
+ Repository.context.pop
+ end
+ end
+ end
+end
@@ -1,26 +1,10 @@
-require __DIR__.parent + 'loaded_set'
+require __DIR__.parent + 'naming_conventions'
+
module DataMapper
module Adapters
-
class AbstractAdapter
-
- # Instantiate an Adapter by passing it a DataMapper::Repository
- # connection string for configuration.
- def initialize(name, uri_or_options)
- @name = name
- @uri = uri(uri_or_options)
-
- @resource_naming_convention = NamingConventions::UnderscoredAndPluralized
- @field_naming_convention = NamingConventions::Underscored
- end
-
- def batch_insertable?
- false
- end
-
attr_reader :name
- attr_accessor :resource_naming_convention
- attr_accessor :field_naming_convention
+ attr_accessor :resource_naming_convention, :field_naming_convention
# Methods dealing with a single resource object
def create(repository, resource)
@@ -66,12 +50,28 @@ def delete_set(repository, query)
# raise ArgumentError unless block_given?
# end
-
def uri(uri_or_options)
uri_or_options
end
- end # class AbstractAdapter
+ def batch_insertable?
+ false
+ end
+
+ private
+
+ # Instantiate an Adapter by passing it a DataMapper::Repository
+ # connection string for configuration.
+ def initialize(name, uri_or_options)
+ raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
+ raise ArgumentError, "+uri_or_options+ should be a Hash, a URI or a String but was #{uri_or_options.class}", caller unless [ Hash, URI, String ].any? { |k| k === uri_or_options }
+
+ @name = name
+ @uri = uri(uri_or_options)
+ @resource_naming_convention = NamingConventions::UnderscoredAndPluralized
+ @field_naming_convention = NamingConventions::Underscored
+ end
+ end # class AbstractAdapter
end # module Adapters
end # module DataMapper
Oops, something went wrong.

0 comments on commit 1e78ba8

Please sign in to comment.