jmonteiro-mongo_mapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/LICENSE +20 -0
- data/README.rdoc +38 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/bin/mmconsole +60 -0
- data/jmonteiro-mongo_mapper.gemspec +195 -0
- data/lib/mongo_mapper.rb +128 -0
- data/lib/mongo_mapper/descendant_appends.rb +44 -0
- data/lib/mongo_mapper/document.rb +402 -0
- data/lib/mongo_mapper/dynamic_finder.rb +74 -0
- data/lib/mongo_mapper/embedded_document.rb +61 -0
- data/lib/mongo_mapper/finder_options.rb +127 -0
- data/lib/mongo_mapper/plugins.rb +19 -0
- data/lib/mongo_mapper/plugins/associations.rb +104 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +121 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +28 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +23 -0
- data/lib/mongo_mapper/plugins/associations/collection.rb +21 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +49 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +139 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +117 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +31 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +23 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +13 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +66 -0
- data/lib/mongo_mapper/plugins/associations/proxy.rb +118 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +65 -0
- data/lib/mongo_mapper/plugins/clone.rb +13 -0
- data/lib/mongo_mapper/plugins/descendants.rb +16 -0
- data/lib/mongo_mapper/plugins/dirty.rb +119 -0
- data/lib/mongo_mapper/plugins/equality.rb +11 -0
- data/lib/mongo_mapper/plugins/identity_map.rb +66 -0
- data/lib/mongo_mapper/plugins/inspect.rb +14 -0
- data/lib/mongo_mapper/plugins/keys.rb +295 -0
- data/lib/mongo_mapper/plugins/logger.rb +17 -0
- data/lib/mongo_mapper/plugins/pagination.rb +85 -0
- data/lib/mongo_mapper/plugins/protected.rb +31 -0
- data/lib/mongo_mapper/plugins/rails.rb +80 -0
- data/lib/mongo_mapper/plugins/serialization.rb +109 -0
- data/lib/mongo_mapper/plugins/validations.rb +48 -0
- data/lib/mongo_mapper/support.rb +213 -0
- data/performance/read_write.rb +52 -0
- data/specs.watchr +51 -0
- data/test/NOTE_ON_TESTING +1 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +63 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +93 -0
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +246 -0
- data/test/functional/associations/test_many_documents_proxy.rb +437 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +175 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +216 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +340 -0
- data/test/functional/associations/test_one_proxy.rb +149 -0
- data/test/functional/test_associations.rb +44 -0
- data/test/functional/test_binary.rb +27 -0
- data/test/functional/test_callbacks.rb +81 -0
- data/test/functional/test_dirty.rb +156 -0
- data/test/functional/test_document.rb +1171 -0
- data/test/functional/test_embedded_document.rb +125 -0
- data/test/functional/test_identity_map.rb +233 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_modifiers.rb +252 -0
- data/test/functional/test_pagination.rb +93 -0
- data/test/functional/test_protected.rb +41 -0
- data/test/functional/test_string_id_compatibility.rb +67 -0
- data/test/functional/test_validations.rb +329 -0
- data/test/models.rb +232 -0
- data/test/support/custom_matchers.rb +55 -0
- data/test/support/timing.rb +16 -0
- data/test/test_helper.rb +60 -0
- data/test/unit/associations/test_base.rb +207 -0
- data/test/unit/associations/test_proxy.rb +103 -0
- data/test/unit/serializers/test_json_serializer.rb +189 -0
- data/test/unit/test_descendant_appends.rb +71 -0
- data/test/unit/test_document.rb +203 -0
- data/test/unit/test_dynamic_finder.rb +125 -0
- data/test/unit/test_embedded_document.rb +628 -0
- data/test/unit/test_finder_options.rb +325 -0
- data/test/unit/test_keys.rb +169 -0
- data/test/unit/test_mongo_mapper.rb +65 -0
- data/test/unit/test_pagination.rb +127 -0
- data/test/unit/test_plugins.rb +42 -0
- data/test/unit/test_rails.rb +139 -0
- data/test/unit/test_rails_compatibility.rb +42 -0
- data/test/unit/test_serialization.rb +51 -0
- data/test/unit/test_support.rb +350 -0
- data/test/unit/test_time_zones.rb +39 -0
- data/test/unit/test_validations.rb +492 -0
- metadata +260 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 John Nunemaker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= MongoMapper
|
2
|
+
|
3
|
+
Awesome gem for modeling your domain and storing it in mongo.
|
4
|
+
|
5
|
+
Releases are tagged on github and released on gemcutter. Master is pushed to whenever I add a patch or a new feature, but I do not release a new gem version each time I push.
|
6
|
+
|
7
|
+
== Note on Patches/Pull Requests
|
8
|
+
|
9
|
+
* Fork the project.
|
10
|
+
* Make your feature addition or bug fix.
|
11
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
12
|
+
* 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)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Install
|
16
|
+
|
17
|
+
$ gem install mongo_mapper
|
18
|
+
|
19
|
+
== Dependencies
|
20
|
+
|
21
|
+
* ActiveSupport (typically the latest version)
|
22
|
+
* Mongo Ruby Driver (mongo)
|
23
|
+
* My fork of the validatable gem (jnunemaker-validatable)
|
24
|
+
|
25
|
+
== Documentation
|
26
|
+
|
27
|
+
Documentation is lacking right now because if you can't look through the code right now and feel comfortable, this is probably too young for you to use. Wait til it stabilizes a bit more.
|
28
|
+
|
29
|
+
http://groups.google.com/group/mongomapper
|
30
|
+
|
31
|
+
== More Info
|
32
|
+
|
33
|
+
* http://www.mongodb.org/
|
34
|
+
* http://github.com/mongodb/mongo-ruby-driver/
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2009 John Nunemaker. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'jeweler'
|
4
|
+
require 'yard'
|
5
|
+
require 'yard/rake/yardoc_task'
|
6
|
+
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "jmonteiro-mongo_mapper"
|
9
|
+
gem.summary = %Q{Awesome gem for modeling your domain and storing it in mongo}
|
10
|
+
gem.email = ["nunemaker@gmail.com", "julio@monteiro.eti.br"]
|
11
|
+
gem.homepage = "http://github.com/jmonteiro/mongomapper"
|
12
|
+
gem.authors = ["John Nunemaker", "Julio Monteiro"]
|
13
|
+
|
14
|
+
gem.add_dependency('activesupport', '>= 2.3')
|
15
|
+
gem.add_dependency('mongo', '0.18.2')
|
16
|
+
gem.add_dependency('jnunemaker-validatable', '1.8.1')
|
17
|
+
|
18
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
19
|
+
gem.add_development_dependency('shoulda', '2.10.2')
|
20
|
+
gem.add_development_dependency('timecop', '0.3.1')
|
21
|
+
gem.add_development_dependency('mocha', '0.9.8')
|
22
|
+
end
|
23
|
+
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'test'
|
29
|
+
test.ruby_opts << '-rubygems'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
namespace :test do
|
35
|
+
Rake::TestTask.new(:units) do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.ruby_opts << '-rubygems'
|
38
|
+
test.pattern = 'test/unit/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
|
42
|
+
Rake::TestTask.new(:functionals) do |test|
|
43
|
+
test.libs << 'test'
|
44
|
+
test.ruby_opts << '-rubygems'
|
45
|
+
test.pattern = 'test/functional/**/test_*.rb'
|
46
|
+
test.verbose = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
task :test => :check_dependencies
|
52
|
+
|
53
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
54
|
+
t.options = ["--legacy"] if RUBY_VERSION < "1.9.0"
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/mmconsole
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'mongo_mapper'
|
6
|
+
require 'irb'
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
retry
|
10
|
+
end
|
11
|
+
|
12
|
+
IRB.setup(nil)
|
13
|
+
irb = IRB::Irb.new
|
14
|
+
|
15
|
+
IRB.conf[:MAIN_CONTEXT] = irb.context
|
16
|
+
|
17
|
+
irb.context.evaluate("require 'irb/completion'", 0)
|
18
|
+
irb.context.evaluate(%@
|
19
|
+
include MongoMapper
|
20
|
+
|
21
|
+
MongoMapper.database = "mmtest"
|
22
|
+
$db = MongoMapper.database
|
23
|
+
|
24
|
+
@, 0)
|
25
|
+
|
26
|
+
puts %@
|
27
|
+
Welcome to the MongoMapper Console!
|
28
|
+
|
29
|
+
Example 1:
|
30
|
+
things = $db.collection("things")
|
31
|
+
things.insert("name" => "Raw Thing")
|
32
|
+
things.insert("name" => "Another Thing", "date" => Time.now)
|
33
|
+
|
34
|
+
cursor = things.find("name" => "Raw Thing")
|
35
|
+
puts cursor.next_object.inspect
|
36
|
+
|
37
|
+
Example 2:
|
38
|
+
class Thing
|
39
|
+
include MongoMapper::Document
|
40
|
+
key :name, String, :required => true
|
41
|
+
key :date, Time
|
42
|
+
end
|
43
|
+
|
44
|
+
thing = Thing.new
|
45
|
+
thing.name = "My thing"
|
46
|
+
thing.date = Time.now
|
47
|
+
thing.save
|
48
|
+
|
49
|
+
all_things = Thing.all
|
50
|
+
puts all_things.map { |object| object.name }.inspect
|
51
|
+
@
|
52
|
+
|
53
|
+
trap("SIGINT") do
|
54
|
+
irb.signal_handle
|
55
|
+
end
|
56
|
+
|
57
|
+
catch(:IRB_EXIT) do
|
58
|
+
irb.eval_input
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jmonteiro-mongo_mapper}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Nunemaker", "Julio Monteiro"]
|
12
|
+
s.date = %q{2010-01-13}
|
13
|
+
s.default_executable = %q{mmconsole}
|
14
|
+
s.email = ["nunemaker@gmail.com", "julio@monteiro.eti.br"]
|
15
|
+
s.executables = ["mmconsole"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bin/mmconsole",
|
27
|
+
"jmonteiro-mongo_mapper.gemspec",
|
28
|
+
"lib/mongo_mapper.rb",
|
29
|
+
"lib/mongo_mapper/descendant_appends.rb",
|
30
|
+
"lib/mongo_mapper/document.rb",
|
31
|
+
"lib/mongo_mapper/dynamic_finder.rb",
|
32
|
+
"lib/mongo_mapper/embedded_document.rb",
|
33
|
+
"lib/mongo_mapper/finder_options.rb",
|
34
|
+
"lib/mongo_mapper/plugins.rb",
|
35
|
+
"lib/mongo_mapper/plugins/associations.rb",
|
36
|
+
"lib/mongo_mapper/plugins/associations/base.rb",
|
37
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb",
|
38
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb",
|
39
|
+
"lib/mongo_mapper/plugins/associations/collection.rb",
|
40
|
+
"lib/mongo_mapper/plugins/associations/embedded_collection.rb",
|
41
|
+
"lib/mongo_mapper/plugins/associations/in_array_proxy.rb",
|
42
|
+
"lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb",
|
43
|
+
"lib/mongo_mapper/plugins/associations/many_documents_proxy.rb",
|
44
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb",
|
45
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb",
|
46
|
+
"lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb",
|
47
|
+
"lib/mongo_mapper/plugins/associations/one_proxy.rb",
|
48
|
+
"lib/mongo_mapper/plugins/associations/proxy.rb",
|
49
|
+
"lib/mongo_mapper/plugins/callbacks.rb",
|
50
|
+
"lib/mongo_mapper/plugins/clone.rb",
|
51
|
+
"lib/mongo_mapper/plugins/descendants.rb",
|
52
|
+
"lib/mongo_mapper/plugins/dirty.rb",
|
53
|
+
"lib/mongo_mapper/plugins/equality.rb",
|
54
|
+
"lib/mongo_mapper/plugins/identity_map.rb",
|
55
|
+
"lib/mongo_mapper/plugins/inspect.rb",
|
56
|
+
"lib/mongo_mapper/plugins/keys.rb",
|
57
|
+
"lib/mongo_mapper/plugins/logger.rb",
|
58
|
+
"lib/mongo_mapper/plugins/pagination.rb",
|
59
|
+
"lib/mongo_mapper/plugins/protected.rb",
|
60
|
+
"lib/mongo_mapper/plugins/rails.rb",
|
61
|
+
"lib/mongo_mapper/plugins/serialization.rb",
|
62
|
+
"lib/mongo_mapper/plugins/validations.rb",
|
63
|
+
"lib/mongo_mapper/support.rb",
|
64
|
+
"performance/read_write.rb",
|
65
|
+
"specs.watchr",
|
66
|
+
"test/NOTE_ON_TESTING",
|
67
|
+
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
68
|
+
"test/functional/associations/test_belongs_to_proxy.rb",
|
69
|
+
"test/functional/associations/test_in_array_proxy.rb",
|
70
|
+
"test/functional/associations/test_many_documents_as_proxy.rb",
|
71
|
+
"test/functional/associations/test_many_documents_proxy.rb",
|
72
|
+
"test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
|
73
|
+
"test/functional/associations/test_many_embedded_proxy.rb",
|
74
|
+
"test/functional/associations/test_many_polymorphic_proxy.rb",
|
75
|
+
"test/functional/associations/test_one_proxy.rb",
|
76
|
+
"test/functional/test_associations.rb",
|
77
|
+
"test/functional/test_binary.rb",
|
78
|
+
"test/functional/test_callbacks.rb",
|
79
|
+
"test/functional/test_dirty.rb",
|
80
|
+
"test/functional/test_document.rb",
|
81
|
+
"test/functional/test_embedded_document.rb",
|
82
|
+
"test/functional/test_identity_map.rb",
|
83
|
+
"test/functional/test_logger.rb",
|
84
|
+
"test/functional/test_modifiers.rb",
|
85
|
+
"test/functional/test_pagination.rb",
|
86
|
+
"test/functional/test_protected.rb",
|
87
|
+
"test/functional/test_string_id_compatibility.rb",
|
88
|
+
"test/functional/test_validations.rb",
|
89
|
+
"test/models.rb",
|
90
|
+
"test/support/custom_matchers.rb",
|
91
|
+
"test/support/timing.rb",
|
92
|
+
"test/test_helper.rb",
|
93
|
+
"test/unit/associations/test_base.rb",
|
94
|
+
"test/unit/associations/test_proxy.rb",
|
95
|
+
"test/unit/serializers/test_json_serializer.rb",
|
96
|
+
"test/unit/test_descendant_appends.rb",
|
97
|
+
"test/unit/test_document.rb",
|
98
|
+
"test/unit/test_dynamic_finder.rb",
|
99
|
+
"test/unit/test_embedded_document.rb",
|
100
|
+
"test/unit/test_finder_options.rb",
|
101
|
+
"test/unit/test_keys.rb",
|
102
|
+
"test/unit/test_mongo_mapper.rb",
|
103
|
+
"test/unit/test_pagination.rb",
|
104
|
+
"test/unit/test_plugins.rb",
|
105
|
+
"test/unit/test_rails.rb",
|
106
|
+
"test/unit/test_rails_compatibility.rb",
|
107
|
+
"test/unit/test_serialization.rb",
|
108
|
+
"test/unit/test_support.rb",
|
109
|
+
"test/unit/test_time_zones.rb",
|
110
|
+
"test/unit/test_validations.rb"
|
111
|
+
]
|
112
|
+
s.homepage = %q{http://github.com/jmonteiro/mongomapper}
|
113
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
114
|
+
s.require_paths = ["lib"]
|
115
|
+
s.rubygems_version = %q{1.3.5}
|
116
|
+
s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
|
117
|
+
s.test_files = [
|
118
|
+
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
119
|
+
"test/functional/associations/test_belongs_to_proxy.rb",
|
120
|
+
"test/functional/associations/test_in_array_proxy.rb",
|
121
|
+
"test/functional/associations/test_many_documents_as_proxy.rb",
|
122
|
+
"test/functional/associations/test_many_documents_proxy.rb",
|
123
|
+
"test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
|
124
|
+
"test/functional/associations/test_many_embedded_proxy.rb",
|
125
|
+
"test/functional/associations/test_many_polymorphic_proxy.rb",
|
126
|
+
"test/functional/associations/test_one_proxy.rb",
|
127
|
+
"test/functional/test_associations.rb",
|
128
|
+
"test/functional/test_binary.rb",
|
129
|
+
"test/functional/test_callbacks.rb",
|
130
|
+
"test/functional/test_dirty.rb",
|
131
|
+
"test/functional/test_document.rb",
|
132
|
+
"test/functional/test_embedded_document.rb",
|
133
|
+
"test/functional/test_identity_map.rb",
|
134
|
+
"test/functional/test_logger.rb",
|
135
|
+
"test/functional/test_modifiers.rb",
|
136
|
+
"test/functional/test_pagination.rb",
|
137
|
+
"test/functional/test_protected.rb",
|
138
|
+
"test/functional/test_string_id_compatibility.rb",
|
139
|
+
"test/functional/test_validations.rb",
|
140
|
+
"test/models.rb",
|
141
|
+
"test/support/custom_matchers.rb",
|
142
|
+
"test/support/timing.rb",
|
143
|
+
"test/test_helper.rb",
|
144
|
+
"test/unit/associations/test_base.rb",
|
145
|
+
"test/unit/associations/test_proxy.rb",
|
146
|
+
"test/unit/serializers/test_json_serializer.rb",
|
147
|
+
"test/unit/test_descendant_appends.rb",
|
148
|
+
"test/unit/test_document.rb",
|
149
|
+
"test/unit/test_dynamic_finder.rb",
|
150
|
+
"test/unit/test_embedded_document.rb",
|
151
|
+
"test/unit/test_finder_options.rb",
|
152
|
+
"test/unit/test_keys.rb",
|
153
|
+
"test/unit/test_mongo_mapper.rb",
|
154
|
+
"test/unit/test_pagination.rb",
|
155
|
+
"test/unit/test_plugins.rb",
|
156
|
+
"test/unit/test_rails.rb",
|
157
|
+
"test/unit/test_rails_compatibility.rb",
|
158
|
+
"test/unit/test_serialization.rb",
|
159
|
+
"test/unit/test_support.rb",
|
160
|
+
"test/unit/test_time_zones.rb",
|
161
|
+
"test/unit/test_validations.rb"
|
162
|
+
]
|
163
|
+
|
164
|
+
if s.respond_to? :specification_version then
|
165
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
166
|
+
s.specification_version = 3
|
167
|
+
|
168
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
169
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
170
|
+
s.add_runtime_dependency(%q<mongo>, ["= 0.18.2"])
|
171
|
+
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
172
|
+
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
173
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
174
|
+
s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
|
175
|
+
s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
|
176
|
+
else
|
177
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
178
|
+
s.add_dependency(%q<mongo>, ["= 0.18.2"])
|
179
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
180
|
+
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
181
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
182
|
+
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
183
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
184
|
+
end
|
185
|
+
else
|
186
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
187
|
+
s.add_dependency(%q<mongo>, ["= 0.18.2"])
|
188
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
189
|
+
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
190
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
191
|
+
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
192
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
data/lib/mongo_mapper.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
# if Gem is defined i'll assume you are using rubygems and lock specific versions
|
4
|
+
# call me crazy but a plain old require will just get the latest version you have installed
|
5
|
+
# so i want to make sure that if you are using gems you do in fact have the correct versions
|
6
|
+
# if there is a better way to do this, please enlighten me!
|
7
|
+
if self.class.const_defined?(:Gem)
|
8
|
+
gem 'activesupport', '>= 2.3'
|
9
|
+
gem 'mongo', '0.18.2'
|
10
|
+
gem 'jnunemaker-validatable', '1.8.1'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'active_support'
|
14
|
+
require 'mongo'
|
15
|
+
require 'validatable'
|
16
|
+
|
17
|
+
module MongoMapper
|
18
|
+
# generic MM error
|
19
|
+
class MongoMapperError < StandardError; end
|
20
|
+
|
21
|
+
# raised when key expected to exist but not found
|
22
|
+
class KeyNotFound < MongoMapperError; end
|
23
|
+
|
24
|
+
# raised when document expected but not found
|
25
|
+
class DocumentNotFound < MongoMapperError; end
|
26
|
+
|
27
|
+
# raised when document not valid and using !
|
28
|
+
class DocumentNotValid < MongoMapperError
|
29
|
+
def initialize(document)
|
30
|
+
super("Validation failed: #{document.errors.full_messages.join(", ")}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @api public
|
35
|
+
def self.connection
|
36
|
+
@@connection ||= Mongo::Connection.new
|
37
|
+
end
|
38
|
+
|
39
|
+
# @api public
|
40
|
+
def self.connection=(new_connection)
|
41
|
+
@@connection = new_connection
|
42
|
+
end
|
43
|
+
|
44
|
+
# @api public
|
45
|
+
def self.logger
|
46
|
+
connection.logger
|
47
|
+
end
|
48
|
+
|
49
|
+
# @api public
|
50
|
+
def self.database=(name)
|
51
|
+
@@database = nil
|
52
|
+
@@database_name = name
|
53
|
+
end
|
54
|
+
|
55
|
+
# @api public
|
56
|
+
def self.database
|
57
|
+
if @@database_name.blank?
|
58
|
+
raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
|
59
|
+
end
|
60
|
+
|
61
|
+
@@database ||= MongoMapper.connection.db(@@database_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @api private
|
65
|
+
def self.ensured_indexes
|
66
|
+
@@ensured_indexes ||= []
|
67
|
+
end
|
68
|
+
|
69
|
+
# @api private
|
70
|
+
def self.ensured_indexes=(value)
|
71
|
+
@@ensured_indexes = value
|
72
|
+
end
|
73
|
+
|
74
|
+
# @api private
|
75
|
+
def self.ensure_index(klass, keys, options={})
|
76
|
+
ensured_indexes << {:klass => klass, :keys => keys, :options => options}
|
77
|
+
end
|
78
|
+
|
79
|
+
# @api public
|
80
|
+
def self.ensure_indexes!
|
81
|
+
ensured_indexes.each do |index|
|
82
|
+
unique = index[:options].delete(:unique)
|
83
|
+
index[:klass].collection.create_index(index[:keys], unique)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @api private
|
88
|
+
def self.use_time_zone?
|
89
|
+
Time.respond_to?(:zone) && Time.zone ? true : false
|
90
|
+
end
|
91
|
+
|
92
|
+
# @api private
|
93
|
+
def self.time_class
|
94
|
+
use_time_zone? ? Time.zone : Time
|
95
|
+
end
|
96
|
+
|
97
|
+
# @api private
|
98
|
+
def self.normalize_object_id(value)
|
99
|
+
value.is_a?(String) ? Mongo::ObjectID.from_string(value) : value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
require 'mongo_mapper/finder_options'
|
104
|
+
require 'mongo_mapper/support'
|
105
|
+
require 'mongo_mapper/descendant_appends'
|
106
|
+
|
107
|
+
require 'mongo_mapper/dynamic_finder'
|
108
|
+
require 'mongo_mapper/key'
|
109
|
+
|
110
|
+
require 'mongo_mapper/plugins'
|
111
|
+
require 'mongo_mapper/plugins/associations'
|
112
|
+
require 'mongo_mapper/plugins/callbacks'
|
113
|
+
require 'mongo_mapper/plugins/clone'
|
114
|
+
require 'mongo_mapper/plugins/descendants'
|
115
|
+
require 'mongo_mapper/plugins/dirty'
|
116
|
+
require 'mongo_mapper/plugins/equality'
|
117
|
+
require 'mongo_mapper/plugins/identity_map'
|
118
|
+
require 'mongo_mapper/plugins/inspect'
|
119
|
+
require 'mongo_mapper/plugins/keys'
|
120
|
+
require 'mongo_mapper/plugins/logger'
|
121
|
+
require 'mongo_mapper/plugins/pagination'
|
122
|
+
require 'mongo_mapper/plugins/protected'
|
123
|
+
require 'mongo_mapper/plugins/rails'
|
124
|
+
require 'mongo_mapper/plugins/serialization'
|
125
|
+
require 'mongo_mapper/plugins/validations'
|
126
|
+
|
127
|
+
require 'mongo_mapper/embedded_document'
|
128
|
+
require 'mongo_mapper/document'
|