djsun-mongomapper 0.3.5.5 → 0.4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +38 -38
- data/Rakefile +87 -73
- data/VERSION +1 -1
- data/lib/mongomapper.rb +67 -71
- data/lib/mongomapper/associations.rb +86 -84
- data/lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb +34 -34
- data/lib/mongomapper/associations/many_embedded_proxy.rb +67 -17
- data/lib/mongomapper/associations/proxy.rb +74 -73
- data/lib/mongomapper/document.rb +342 -348
- data/lib/mongomapper/embedded_document.rb +354 -274
- data/lib/mongomapper/finder_options.rb +84 -84
- data/lib/mongomapper/key.rb +32 -76
- data/lib/mongomapper/rails_compatibility/document.rb +14 -14
- data/lib/mongomapper/rails_compatibility/embedded_document.rb +26 -24
- data/lib/mongomapper/support.rb +156 -29
- data/lib/mongomapper/validations.rb +69 -47
- data/test/custom_matchers.rb +48 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +53 -56
- data/test/functional/associations/test_belongs_to_proxy.rb +48 -49
- data/test/functional/associations/test_many_documents_as_proxy.rb +208 -253
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +130 -130
- data/test/functional/associations/test_many_embedded_proxy.rb +168 -106
- data/test/functional/associations/test_many_polymorphic_proxy.rb +261 -262
- data/test/functional/test_binary.rb +21 -0
- data/test/functional/test_document.rb +946 -952
- data/test/functional/test_embedded_document.rb +98 -0
- data/test/functional/test_pagination.rb +87 -80
- data/test/functional/test_rails_compatibility.rb +29 -29
- data/test/functional/test_validations.rb +262 -172
- data/test/models.rb +169 -169
- data/test/test_helper.rb +28 -66
- data/test/unit/serializers/test_json_serializer.rb +193 -193
- data/test/unit/test_document.rb +161 -123
- data/test/unit/test_embedded_document.rb +643 -547
- data/test/unit/test_finder_options.rb +183 -183
- data/test/unit/test_key.rb +175 -247
- data/test/unit/test_rails_compatibility.rb +38 -33
- data/test/unit/test_serializations.rb +52 -52
- data/test/unit/test_support.rb +268 -0
- data/test/unit/test_time_zones.rb +40 -0
- data/test/unit/test_validations.rb +499 -258
- metadata +22 -12
- data/History +0 -76
- data/mongomapper.gemspec +0 -145
data/README.rdoc
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
= MongoMapper
|
2
|
-
|
3
|
-
Awesome gem for modeling your domain and storing it in mongo.
|
4
|
-
|
5
|
-
Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
|
6
|
-
|
7
|
-
* rake gemspec
|
8
|
-
* gem build mongomapper.gemspec
|
9
|
-
* gem install the gem that was built
|
10
|
-
|
11
|
-
== Note on Patches/Pull Requests
|
12
|
-
|
13
|
-
* Fork the project.
|
14
|
-
* Make your feature addition or bug fix.
|
15
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
17
|
-
* Send me a pull request. Bonus points for topic branches.
|
18
|
-
|
19
|
-
== Dependencies
|
20
|
-
|
21
|
-
* ActiveSupport (activesupport)
|
22
|
-
* Mongo Ruby Driver (
|
23
|
-
* My fork of the validatable gem (jnunemaker-validatable)
|
24
|
-
|
25
|
-
== Documentation
|
26
|
-
|
27
|
-
http://rdoc.info/projects/jnunemaker/mongomapper
|
28
|
-
|
29
|
-
== More Info
|
30
|
-
|
31
|
-
You can learn more about mongo here:
|
32
|
-
http://www.mongodb.org/
|
33
|
-
|
34
|
-
You can learn more about the mongo ruby driver here:
|
35
|
-
http://github.com/mongodb/mongo-ruby-driver/tree/master
|
36
|
-
|
37
|
-
== Copyright
|
38
|
-
|
1
|
+
= MongoMapper
|
2
|
+
|
3
|
+
Awesome gem for modeling your domain and storing it in mongo.
|
4
|
+
|
5
|
+
Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
|
6
|
+
|
7
|
+
* rake gemspec
|
8
|
+
* gem build mongomapper.gemspec
|
9
|
+
* gem install the gem that was built
|
10
|
+
|
11
|
+
== Note on Patches/Pull Requests
|
12
|
+
|
13
|
+
* Fork the project.
|
14
|
+
* Make your feature addition or bug fix.
|
15
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
17
|
+
* Send me a pull request. Bonus points for topic branches.
|
18
|
+
|
19
|
+
== Dependencies
|
20
|
+
|
21
|
+
* ActiveSupport (activesupport)
|
22
|
+
* Mongo Ruby Driver (mongo)
|
23
|
+
* My fork of the validatable gem (jnunemaker-validatable)
|
24
|
+
|
25
|
+
== Documentation
|
26
|
+
|
27
|
+
http://rdoc.info/projects/jnunemaker/mongomapper
|
28
|
+
|
29
|
+
== More Info
|
30
|
+
|
31
|
+
You can learn more about mongo here:
|
32
|
+
http://www.mongodb.org/
|
33
|
+
|
34
|
+
You can learn more about the mongo ruby driver here:
|
35
|
+
http://github.com/mongodb/mongo-ruby-driver/tree/master
|
36
|
+
|
37
|
+
== Copyright
|
38
|
+
|
39
39
|
Copyright (c) 2009 John Nunemaker. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,73 +1,87 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "mongomapper"
|
8
|
-
gem.summary = %Q{
|
9
|
-
gem.email = "
|
10
|
-
gem.homepage = "http://github.com/
|
11
|
-
gem.authors = ["John Nunemaker"]
|
12
|
-
gem.rubyforge_project = "mongomapper"
|
13
|
-
|
14
|
-
gem.add_dependency('activesupport')
|
15
|
-
gem.add_dependency('
|
16
|
-
gem.add_dependency('jnunemaker-validatable', '1.7.2')
|
17
|
-
|
18
|
-
gem.add_development_dependency('mocha', '0.9.4')
|
19
|
-
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
20
|
-
end
|
21
|
-
|
22
|
-
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
-
rubyforge.doc_task = "rdoc"
|
24
|
-
end
|
25
|
-
rescue LoadError
|
26
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
27
|
-
end
|
28
|
-
|
29
|
-
require 'rake/testtask'
|
30
|
-
Rake::TestTask.new(:test) do |test|
|
31
|
-
test.libs << 'lib' << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
test.
|
40
|
-
test.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
task :
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "djsun-mongomapper"
|
8
|
+
gem.summary = %Q{Map your domain to MongoDB}
|
9
|
+
gem.email = "djames@sunlightfoundation.com"
|
10
|
+
gem.homepage = "http://github.com/djsun/mongomapper"
|
11
|
+
gem.authors = ["John Nunemaker", "David James"]
|
12
|
+
# gem.rubyforge_project = "djsun-mongomapper"
|
13
|
+
|
14
|
+
gem.add_dependency('activesupport')
|
15
|
+
gem.add_dependency('mongo', '0.15')
|
16
|
+
gem.add_dependency('jnunemaker-validatable', '1.7.2')
|
17
|
+
|
18
|
+
gem.add_development_dependency('mocha', '0.9.4')
|
19
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
20
|
+
end
|
21
|
+
|
22
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
+
rubyforge.doc_task = "rdoc"
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :test do
|
37
|
+
Rake::TestTask.new(:units) do |test|
|
38
|
+
test.libs << 'lib' << 'test'
|
39
|
+
test.pattern = 'test/unit/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::TestTask.new(:functionals) do |test|
|
44
|
+
test.libs << 'lib' << 'test'
|
45
|
+
test.pattern = 'test/functional/**/test_*.rb'
|
46
|
+
test.verbose = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
require 'rcov/rcovtask'
|
52
|
+
Rcov::RcovTask.new do |test|
|
53
|
+
test.libs << 'test'
|
54
|
+
test.pattern = 'test/**/test_*.rb'
|
55
|
+
test.verbose = true
|
56
|
+
end
|
57
|
+
rescue LoadError
|
58
|
+
task :rcov do
|
59
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
begin
|
64
|
+
require 'cucumber/rake/task'
|
65
|
+
Cucumber::Rake::Task.new(:features)
|
66
|
+
rescue LoadError
|
67
|
+
task :features do
|
68
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
task :default => :test
|
73
|
+
|
74
|
+
require 'rake/rdoctask'
|
75
|
+
Rake::RDocTask.new do |rdoc|
|
76
|
+
if File.exist?('VERSION.yml')
|
77
|
+
config = YAML.load(File.read('VERSION.yml'))
|
78
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
79
|
+
else
|
80
|
+
version = ""
|
81
|
+
end
|
82
|
+
|
83
|
+
rdoc.rdoc_dir = 'rdoc'
|
84
|
+
rdoc.title = "MongoMapper #{version}"
|
85
|
+
rdoc.rdoc_files.include('README*')
|
86
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
87
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.1.2
|
data/lib/mongomapper.rb
CHANGED
@@ -1,71 +1,67 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
gem '
|
5
|
-
gem '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require '
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require
|
15
|
-
|
16
|
-
require
|
17
|
-
require
|
18
|
-
|
19
|
-
require
|
20
|
-
require
|
21
|
-
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@@
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.
|
61
|
-
@@
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@@database
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.database
|
69
|
-
@@database
|
70
|
-
end
|
71
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'activesupport'
|
4
|
+
gem 'mongo', '0.15'
|
5
|
+
gem 'jnunemaker-validatable', '1.7.2'
|
6
|
+
|
7
|
+
require 'activesupport'
|
8
|
+
require 'mongo'
|
9
|
+
require 'validatable'
|
10
|
+
|
11
|
+
require 'mongomapper/support'
|
12
|
+
require 'mongomapper/associations'
|
13
|
+
require 'mongomapper/associations/base'
|
14
|
+
require 'mongomapper/associations/proxy'
|
15
|
+
require 'mongomapper/associations/many_documents_proxy'
|
16
|
+
require 'mongomapper/associations/belongs_to_proxy'
|
17
|
+
require 'mongomapper/associations/belongs_to_polymorphic_proxy'
|
18
|
+
require 'mongomapper/associations/many_proxy'
|
19
|
+
require 'mongomapper/associations/many_polymorphic_proxy'
|
20
|
+
require 'mongomapper/associations/many_embedded_proxy'
|
21
|
+
require 'mongomapper/associations/many_embedded_polymorphic_proxy'
|
22
|
+
require 'mongomapper/associations/many_documents_as_proxy'
|
23
|
+
require 'mongomapper/callbacks'
|
24
|
+
require 'mongomapper/finder_options'
|
25
|
+
require 'mongomapper/dynamic_finder'
|
26
|
+
require 'mongomapper/key'
|
27
|
+
require 'mongomapper/observing'
|
28
|
+
require 'mongomapper/pagination'
|
29
|
+
require 'mongomapper/save_with_validation'
|
30
|
+
require 'mongomapper/serialization'
|
31
|
+
require 'mongomapper/validations'
|
32
|
+
require 'mongomapper/rails_compatibility/document'
|
33
|
+
require 'mongomapper/rails_compatibility/embedded_document'
|
34
|
+
require 'mongomapper/embedded_document'
|
35
|
+
require 'mongomapper/document'
|
36
|
+
|
37
|
+
module MongoMapper
|
38
|
+
DocumentNotFound = Class.new(StandardError)
|
39
|
+
|
40
|
+
DocumentNotValid = Class.new(StandardError) do
|
41
|
+
def initialize(document)
|
42
|
+
@document = document
|
43
|
+
super("Validation failed: #{@document.errors.full_messages.join(", ")}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.connection
|
48
|
+
@@connection ||= Mongo::Connection.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.connection=(new_connection)
|
52
|
+
@@connection = new_connection
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.database=(name)
|
56
|
+
@@database = nil
|
57
|
+
@@database_name = name
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.database
|
61
|
+
if @@database_name.blank?
|
62
|
+
raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
|
63
|
+
end
|
64
|
+
|
65
|
+
@@database ||= MongoMapper.connection.db(@@database_name)
|
66
|
+
end
|
67
|
+
end
|
@@ -1,84 +1,86 @@
|
|
1
|
-
module MongoMapper
|
2
|
-
module Associations
|
3
|
-
module ClassMethods
|
4
|
-
def belongs_to(association_id, options = {})
|
5
|
-
create_association(:belongs_to, association_id, options)
|
6
|
-
self
|
7
|
-
end
|
8
|
-
|
9
|
-
def many(association_id, options = {})
|
10
|
-
create_association(:many, association_id, options)
|
11
|
-
self
|
12
|
-
end
|
13
|
-
|
14
|
-
def associations
|
15
|
-
@associations ||=
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
association
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
when :
|
56
|
-
doc.get_proxy(association).
|
57
|
-
when :
|
58
|
-
doc.get_proxy(association).
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
1
|
+
module MongoMapper
|
2
|
+
module Associations
|
3
|
+
module ClassMethods
|
4
|
+
def belongs_to(association_id, options = {})
|
5
|
+
create_association(:belongs_to, association_id, options)
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def many(association_id, options = {})
|
10
|
+
create_association(:many, association_id, options)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def associations
|
15
|
+
@associations ||= self.superclass.respond_to?(:associations) ?
|
16
|
+
self.superclass.associations :
|
17
|
+
HashWithIndifferentAccess.new
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def create_association(type, name, options)
|
22
|
+
association = Associations::Base.new(type, name, options)
|
23
|
+
associations[association.name] = association
|
24
|
+
define_association_methods(association)
|
25
|
+
define_dependent_callback(association)
|
26
|
+
association
|
27
|
+
end
|
28
|
+
|
29
|
+
def define_association_methods(association)
|
30
|
+
define_method(association.name) do
|
31
|
+
get_proxy(association)
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method("#{association.name}=") do |value|
|
35
|
+
get_proxy(association).replace(value)
|
36
|
+
value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def define_dependent_callback(association)
|
41
|
+
if association.options[:dependent]
|
42
|
+
if association.many?
|
43
|
+
define_dependent_callback_for_many(association)
|
44
|
+
elsif association.belongs_to?
|
45
|
+
define_dependent_callback_for_belongs_to(association)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def define_dependent_callback_for_many(association)
|
51
|
+
return if association.embeddable?
|
52
|
+
|
53
|
+
after_destroy do |doc|
|
54
|
+
case association.options[:dependent]
|
55
|
+
when :destroy
|
56
|
+
doc.get_proxy(association).destroy_all
|
57
|
+
when :delete_all
|
58
|
+
doc.get_proxy(association).delete_all
|
59
|
+
when :nullify
|
60
|
+
doc.get_proxy(association).nullify
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def define_dependent_callback_for_belongs_to(association)
|
66
|
+
after_destroy do |doc|
|
67
|
+
case association.options[:dependent]
|
68
|
+
when :destroy
|
69
|
+
doc.get_proxy(association).destroy
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module InstanceMethods
|
76
|
+
def get_proxy(association)
|
77
|
+
unless proxy = self.instance_variable_get(association.ivar)
|
78
|
+
proxy = association.proxy_class.new(self, association)
|
79
|
+
self.instance_variable_set(association.ivar, proxy) if !frozen?
|
80
|
+
end
|
81
|
+
|
82
|
+
proxy
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|