Permalink
Browse files

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

  • Loading branch information...
2 parents 01d1e2a + ad25cbf commit a2e7c57f5889044b2203d187becb59ed5aafc177 @david david committed Apr 21, 2008
Showing with 651 additions and 10,536 deletions.
  1. +14 −7 Rakefile
  2. +0 −111 burn/associations.rb
  3. +0 −160 burn/associations/belongs_to_association.rb
  4. +0 −437 burn/associations/has_and_belongs_to_many_association.rb
  5. +0 −283 burn/associations/has_many_association.rb
  6. +0 −143 burn/associations/has_n_association.rb
  7. +0 −47 burn/associations/reference.rb
  8. +0 −107 burn/callbacks.rb
  9. +0 −166 burn/container.rb
  10. +0 −109 burn/context.rb
  11. +0 −145 burn/embedded_value.rb
  12. +0 −7 burn/example.rb
  13. +0 −155 burn/migration.rb
  14. +0 −13 burn/model.rb
  15. +0 −769 burn/persistable.rb
  16. +0 −1 burn/plugins/.gitignore
  17. +0 −23 burn/plugins/can_has_sphinx/LICENSE
  18. +0 −4 burn/plugins/can_has_sphinx/README
  19. +0 −1 burn/plugins/can_has_sphinx/REVISION
  20. +0 −22 burn/plugins/can_has_sphinx/Rakefile
  21. +0 −1 burn/plugins/can_has_sphinx/init.rb
  22. +0 −1 burn/plugins/can_has_sphinx/install.rb
  23. +0 −123 burn/plugins/can_has_sphinx/lib/acts_as_sphinx.rb
  24. +0 −460 burn/plugins/can_has_sphinx/lib/sphinx.rb
  25. +0 −47 burn/plugins/can_has_sphinx/scripts/sphinx.sh
  26. +0 −45 burn/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake
  27. +0 −67 burn/spec/acts_as_tree_spec.rb
  28. +0 −98 burn/spec/associations/belongs_to_association_spec.rb
  29. +0 −377 burn/spec/associations/has_and_belongs_to_many_association_spec.rb
  30. +0 −337 burn/spec/associations/has_many_association_spec.rb
  31. +0 −52 burn/spec/attributes_spec.rb
  32. +0 −100 burn/spec/auto_migrations_spec.rb
  33. +0 −186 burn/spec/callbacks_spec.rb
  34. +0 −41 burn/spec/coersion_spec.rb
  35. +0 −114 burn/spec/column_spec.rb
  36. +0 −83 burn/spec/container_spec.rb
  37. +0 −45 burn/spec/count_command_spec.rb
  38. +0 −18 burn/spec/database_spec.rb
  39. +0 −27 burn/spec/dataobjects_spec.rb
  40. +0 −11 burn/spec/delete_command_spec.rb
  41. +0 −161 burn/spec/embedded_value_spec.rb
  42. +0 −33 burn/spec/fixtures/animals.yaml
  43. +0 −2 burn/spec/fixtures/animals_exhibits.yaml
  44. +0 −5 burn/spec/fixtures/careers.yaml
  45. +0 −1 burn/spec/fixtures/comments.yaml
  46. +0 −90 burn/spec/fixtures/exhibits.yaml
  47. +0 −6 burn/spec/fixtures/fruit.yaml
  48. +0 −37 burn/spec/fixtures/people.yaml
  49. +0 −3 burn/spec/fixtures/posts.yaml
  50. +0 −13 burn/spec/fixtures/projects.yaml
  51. +0 −5 burn/spec/fixtures/sections.yaml
  52. +0 −6 burn/spec/fixtures/serializers.yaml
  53. +0 −6 burn/spec/fixtures/tasks.yaml
  54. +0 −2 burn/spec/fixtures/tasks_tasks.yaml
  55. +0 −1 burn/spec/fixtures/tomatoes.yaml
  56. +0 −1 burn/spec/fixtures/users.yaml
  57. +0 −24 burn/spec/fixtures/zoos.yaml
  58. +0 −149 burn/spec/is_a_tree_spec.rb
  59. +0 −16 burn/spec/legacy_spec.rb
  60. +0 −322 burn/spec/load_command_spec.rb
  61. +0 −26 burn/spec/magic_columns_spec.rb
  62. +0 −267 burn/spec/migration_spec.rb
  63. +0 −12 burn/spec/models/animal.rb
  64. +0 −8 burn/spec/models/candidate.rb
  65. +0 −7 burn/spec/models/career.rb
  66. +0 −8 burn/spec/models/chain.rb
  67. +0 −6 burn/spec/models/comment.rb
  68. +0 −14 burn/spec/models/exhibit.rb
  69. +0 −7 burn/spec/models/fence.rb
  70. +0 −8 burn/spec/models/fruit.rb
  71. +0 −9 burn/spec/models/job.rb
  72. +0 −31 burn/spec/models/person.rb
  73. +0 −14 burn/spec/models/post.rb
  74. +0 −41 burn/spec/models/project.rb
  75. +0 −5 burn/spec/models/sales_person.rb
  76. +0 −8 burn/spec/models/section.rb
  77. +0 −5 burn/spec/models/serializer.rb
  78. +0 −9 burn/spec/models/task.rb
  79. +0 −25 burn/spec/models/tomato.rb
  80. +0 −13 burn/spec/models/user.rb
  81. +0 −13 burn/spec/models/zoo.rb
  82. +0 −36 burn/spec/natural_key_spec.rb
  83. +0 −38 burn/spec/paranoia_spec.rb
  84. +0 −479 burn/spec/persistable_spec.rb
  85. +0 −96 burn/spec/postgres_spec.rb
  86. +0 −77 burn/spec/query_spec.rb
  87. +0 −94 burn/spec/save_command_spec.rb
  88. +0 −5 burn/spec/schema_spec.rb
  89. +0 −19 burn/spec/serialize_spec.rb
  90. +0 −43 burn/spec/single_table_inheritance_spec.rb
  91. +0 −41 burn/spec/support/inflector_spec.rb
  92. +0 −61 burn/spec/support/serialization_spec.rb
  93. +0 −15 burn/spec/support/silence_spec.rb
  94. +0 −28 burn/spec/support/symbolic_operators_spec.rb
  95. +0 −66 burn/spec/support/typed_set_spec.rb
  96. +0 −79 burn/spec/table_spec.rb
  97. +0 −81 burn/spec/types/string.rb
  98. +0 −55 burn/spec/validates_confirmation_of_spec.rb
  99. +0 −77 burn/spec/validates_format_of_spec.rb
  100. +0 −117 burn/spec/validates_length_of_spec.rb
  101. +0 −92 burn/spec/validates_uniqueness_of_spec.rb
  102. +0 −59 burn/spec/validations/number_validator.rb
  103. +0 −14 burn/spec/validations/string_validator.rb
  104. +0 −141 burn/spec/validations_spec.rb
  105. +0 −134 burn/sql/coersion.rb
  106. +0 −545 burn/sql/commands/load_command.rb
  107. +0 −34 burn/sql/mappings/associations_set.rb
  108. +0 −279 burn/sql/mappings/column.rb
  109. +0 −172 burn/sql/mappings/conditions.rb
  110. +0 −459 burn/sql/mappings/table.rb
  111. +0 −24 burn/sql/quoting.rb
  112. +0 −117 burn/support/connection_pool.rb
  113. +0 −10 burn/support/silence.rb
  114. +0 −68 burn/support/typed_set.rb
  115. +0 −12 burn/validatable_extensions/errors.rb
  116. +0 −7 burn/validatable_extensions/macros.rb
  117. +0 −62 burn/validatable_extensions/validatable_instance_methods.rb
  118. +0 −18 burn/validatable_extensions/validation_base.rb
  119. +0 −43 burn/validatable_extensions/validations/formats/email.rb
  120. +0 −7 burn/validatable_extensions/validations/validates_acceptance_of.rb
  121. +0 −7 burn/validatable_extensions/validations/validates_confirmation_of.rb
  122. +0 −7 burn/validatable_extensions/validations/validates_each.rb
  123. +0 −28 burn/validatable_extensions/validations/validates_format_of.rb
  124. +0 −15 burn/validatable_extensions/validations/validates_length_of.rb
  125. +0 −7 burn/validatable_extensions/validations/validates_numericality_of.rb
  126. +0 −7 burn/validatable_extensions/validations/validates_presence_of.rb
  127. +0 −7 burn/validatable_extensions/validations/validates_true_for.rb
  128. +0 −40 burn/validatable_extensions/validations/validates_uniqueness_of.rb
  129. +0 −20 burn/validations.rb
  130. +2 −0 environment.rb
  131. +19 −12 lib/data_mapper.rb
  132. +9 −9 lib/data_mapper/adapters/data_objects_adapter.rb
  133. +11 −13 lib/data_mapper/adapters/sqlite3_adapter.rb
  134. +76 −19 lib/data_mapper/associations.rb
  135. +3 −0 lib/data_mapper/associations/many_to_many.rb
  136. +4 −2 lib/data_mapper/associations/many_to_one.rb
  137. +3 −0 lib/data_mapper/associations/one_to_many.rb
  138. +6 −5 lib/data_mapper/associations/one_to_one.rb
  139. +12 −4 lib/data_mapper/associations/parent_to_child_association.rb
  140. +37 −27 lib/data_mapper/loaded_set.rb
  141. +9 −15 lib/data_mapper/logger.rb
  142. +1 −17 lib/data_mapper/property.rb
  143. +27 −27 lib/data_mapper/query.rb
  144. +1 −0 lib/data_mapper/repository.rb
  145. +11 −11 lib/data_mapper/resource.rb
  146. +37 −0 lib/data_mapper/types/enum.rb
  147. +48 −0 lib/data_mapper/types/flag.rb
  148. +9 −3 spec/integration/postgres_adapter_spec.rb
  149. +152 −0 spec/unit/associations_spec.rb
  150. +0 −1 spec/unit/loaded_set_spec.rb
  151. +7 −6 spec/unit/property_spec.rb
  152. +7 −12 spec/unit/resource_spec.rb
  153. +64 −0 spec/unit/types/enum_spec.rb
  154. +82 −0 spec/unit/types/flag_spec.rb
  155. +0 −49 tasks/fixtures.rb
View
@@ -13,10 +13,13 @@ require Pathname(__FILE__).dirname.expand_path + 'lib/data_mapper/support/kernel
Pathname.glob(__DIR__ + 'tasks/**/*.rb') { |t| require t }
-task :default => 'dm:spec'
-
+task :default => 'dm:spec'
+task :spec => 'dm:spec'
task :environment => 'dm:environment'
+desc 'Remove all package, rdocs and spec products'
+task :clobber_all => %w[ clobber_package clobber_rdoc dm:clobber_spec ]
+
namespace :dm do
desc "Setup Environment"
task :environment do
@@ -55,7 +58,7 @@ namespace :dm do
desc "Profile DataMapper"
task :profile do
- load __DIR__ + 'script/profile_data_mapper.rb'
+ load __DIR__ + 'script/profile.rb'
end
end
@@ -80,6 +83,7 @@ end
PROJECT = "dm-core"
+desc 'List all package files'
task :ls do
puts PACKAGE_FILES
end
@@ -132,13 +136,16 @@ task :rubyforge => [ :rdoc, :gem ] do
Rake::SshDirPublisher.new("#{ENV['RUBYFORGE_USER']}@rubyforge.org", "/var/www/gforge-projects/#{PROJECT}", 'doc').upload
end
+desc "Install #{PROJECT}"
task :install => :package do
sh %{sudo gem install pkg/#{PROJECT}-#{PACKAGE_VERSION}}
end
-namespace :dev do
- desc "Install for development (for windows)"
- task :winstall => :gem do
- system %{gem install --no-rdoc --no-ri -l pkg/#{PROJECT}-#{PACKAGE_VERSION}.gem}
+if RUBY_PLATFORM.match(/mswin32|cygwin|mingw|bccwin/)
+ namespace :dev do
+ desc 'Install for development (for windows)'
+ task :winstall => :gem do
+ system %{gem install --no-rdoc --no-ri -l pkg/#{PROJECT}-#{PACKAGE_VERSION}.gem}
+ end
end
end
View
@@ -1,111 +0,0 @@
-require File.join(File.dirname(__FILE__), 'associations', 'reference')
-require File.join(File.dirname(__FILE__), 'associations', 'has_many_association')
-require File.join(File.dirname(__FILE__), 'associations', 'belongs_to_association')
-require File.join(File.dirname(__FILE__), 'associations', 'has_and_belongs_to_many_association')
-
-module DataMapper
- module Associations
-
- # Extends +base+ with methods for setting up associations between different models.
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
-
- def associations
- @associations
- end
-
- # Adds the following methods for query of a single associated object:
- # * <tt>collection(</tt> - returns a set containing the associated objects. Returns
- # an empty set if no objects are found.
- # * <tt>collection << object</tt> - adds an object to the collection.
- # * <tt>collection = [objects]</tt> - replaces the collections content by deleting and
- # adding objects as appropriate.
- # * <tt>collection.empty?</tt> - returns +true+ if there is no associated objects.
- # * <tt>collection.size</tt> - returns the number of associated objects.
- #
- # Options are:
- # * <tt>:class</tt> - specify the class name of the association. So has_many :animals will by
- # default be linked to the Animal class, but if you want the association to use a
- # different class, you'll have to specify it with this option. DM also lets you specify
- # this with <tt>:class_name</tt>, for AR compability.
- # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default
- # this is guessed to be the name of this class in lower-case and _id suffixed.
- # * <tt>:dependent</tt> - if set to :destroy, the associated objects have their destroy! methods
- # called in a chain meaning all callbacks are also called for each object.
- # if set to :delete, the associated objects are deleted from the database
- # without their callbacks being triggered.
- # if set to :protect and the collection is not empty an AssociatedProtectedError will be raised.
- # if set to :nullify, the associated objects foreign key is set to NULL.
- # default is :nullify
- #
- # Option examples:
- # has_many :favourite_fruits, :class => 'Fruit', :dependent => :destroy
- def has_many(association_name, options = {})
- #self.associations << HasManyAssociation.new(self, association_name, options)
- end
-
- # Adds the following methods for query of a single associated object:
- # * <tt>association(</tt> - returns the associated object. Returns an empty set if no
- # object is found.
- # * <tt>association=(associate)</tt> - assigns the associate object, extracts the
- # primary key, and sets it as the foreign key.
- # * <tt>association.nil?</tt> - returns +true+ if there is no associated object.
- #
- # The declaration can also include an options hash to specialize the behavior of the
- # association.
- #
- # Options are:
- # * <tt>:class</tt> - specify the class name of the association. So has_one :animal will by
- # default be linked to the Animal class, but if you want the association to use a
- # different class, you'll have to specify it with this option. DM also lets you specify
- # this with <tt>:class_name</tt>, for AR compability.
- # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default
- # this is guessed to be the name of this class in lower-case and _id suffixed.
- # * <tt>:dependent</tt> - has_one is secretly a has_many so this option performs the same
- # as the has_many
- #
- # Option examples:
- # has_one :favourite_fruit, :class => 'Fruit', :foreign_key => 'devourer_id'
- def has_one(association_name, options = {})
- #self.associations << HasManyAssociation.new(self, association_name, options)
- end
-
- # Adds the following methods for query of a single associated object:
- # * <tt>association(</tt> - returns the associated object. Returns an empty set if no
- # object is found.
- # * <tt>association=(associate)</tt> - assigns the associate object, extracts the
- # primary key, and sets it as the foreign key.
- # * <tt>association.nil?</tt> - returns +true+ if there is no associated object.
- # * <tt>build_association</tt> - builds a new object of the associated type, without
- # saving it to the database.
- # * <tt>create_association</tt> - creates and saves a new object of the associated type.
- def belongs_to(association_name, options = {})
- #self.associations << BelongsToAssociation.new(self, association_name, options)
- end
-
- # Associates two classes via an intermediate join table.
- #
- # Options are:
- # * <tt>:dependent</tt> - if set to :destroy, the associated objects have their destroy! methods
- # called in a chain meaning all callbacks are also called for each object. Beware that this
- # is a cascading delete and will affect all records that have a remote relationship with the
- # record being destroyed!
- # if set to :delete, the associated objects are deleted from the database without their
- # callbacks being triggered. This does NOT cascade the deletes. All associated objects will
- # have their relationships removed from other records before being deleted. The record calling
- # destroy will only delete those records directly associated to it.
- # if set to :protect and the collection is not empty an AssociatedProtectedError will be raised.
- # if set to :nullify, the join table will have the relationship records removed which is
- # effectively nullifying the foreign key.
- # default is :nullify
- def has_and_belongs_to_many(association_name, options = {})
- #self.associations << HasAndBelongsToManyAssociation.new(self, association_name, options)
- end
-
- end
-
- end
-end
@@ -1,160 +0,0 @@
-require File.join(File.dirname(__FILE__), 'has_n_association')
-
-module DataMapper
- module Associations
-
- class BelongsToAssociation < HasNAssociation
-
- def define_accessor(klass)
- klass.class_eval <<-EOS
-
- def create_#{@association_name}(options = {})
- #{@association_name}_association.create(options)
- end
-
- def build_#{@association_name}(options = {})
- #{@association_name}_association.build(options)
- end
-
- def #{@association_name}
- #{@association_name}_association.instance
- end
-
- def #{@association_name}=(value)
- #{@association_name}_association.set(value)
- end
-
- private
- def #{@association_name}_association
- @#{@association_name} || (@#{@association_name} = DataMapper::Associations::BelongsToAssociation::Instance.new(self, #{@association_name.inspect}))
- end
- EOS
- end
-
- # Reverse the natural order for BelongsToAssociations
- alias constant associated_constant
- def associated_constant
- @constant
- end
-
- def foreign_key_name
- @foreign_key_name || @foreign_key_name = (@options[:foreign_key] || "#{name}_#{key_table.key.name}".to_sym)
- end
-
- def complementary_association
- @complementary_association || begin
- @complementary_association = key_table.associations.find do |mapping|
- mapping.is_a?(HasManyAssociation) &&
- mapping.foreign_key_column.name == foreign_key_column.name &&
- mapping.associated_table.name == associated_table.name
- end
-
- if @complementary_association
- class << self
- attr_accessor :complementary_association
- end
- end
-
- return @complementary_association
- end
- end
-
- def to_sql # :nodoc:
- "JOIN #{key_table.to_sql} ON #{foreign_key_column.to_sql(true)} = #{primary_key_column.to_sql(true)}"
- end
-
- class Instance < Associations::Reference
-
- def dirty?(cleared = ::Set.new)
- @associated && (@new_member || @key_not_set)
- end
-
- def validate_recursively(event, cleared)
- @associated.nil? || cleared.include?(@associated) || @associated.validate_recursively(event, cleared)
- end
-
- def save_without_validation(database_context, cleared)
- @new_member = false
- unless @associated.nil?
- @instance.instance_variable_set(
- association.foreign_key_column.instance_variable_name,
- @associated.key
- )
- @instance.database_context.adapter.save_without_validation(database_context, @instance, cleared)
- end
- end
-
- def reload!
- @new_member = false
- @associated = nil
- instance
- end
-
- def instance
- @associated || @associated = begin
- if @instance.loaded_set.nil?
- nil
- else
-
- # Temp variable for the instance variable name.
- fk = association.foreign_key_column.to_sym
-
- set = @instance.loaded_set.group_by { |instance| instance.send(fk) }
-
- @instance.database_context.all(association.constant, association.associated_table.key.to_sym => set.keys).each do |assoc|
- set[assoc.key].each do |primary_instance|
- primary_instance.send("#{@association_name}_association").shallow_append(assoc)
- end
- end
-
- @associated
- end
- end
- end
-
- def create(options)
- @associated = association.associated_constant.create(options)
- end
-
- def build(options)
- @associated = association.associated_constant.new(options)
- end
-
- def setter_method
- "#{@association_name}=".to_sym
- end
-
- def set(member)
- shallow_append(member)
-
- if complement = association.complementary_association
- member.send(complement.name).shallow_append(@instance)
- end
-
- return self
- end
-
- def shallow_append(val)
- raise RecursionError.new if val == @instance
- @instance.instance_variable_set(association.foreign_key_column.instance_variable_name, val.key)
- @associated = val
- @key_not_set = true if val.key.nil?
- return self
- end
-
- def deactivate
- end
-
- private
-
- def ensure_foreign_key!
- if @associated
- @instance.instance_variable_set(association.foreign_key.instance_variable_name, @associated.key)
- end
- end
-
- end # class Instance
- end
-
- end
-end
Oops, something went wrong.

0 comments on commit a2e7c57

Please sign in to comment.