mongo_mapper_ign 0.7.4 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/mongo_mapper.rb +5 -8
- data/lib/mongo_mapper/document.rb +24 -53
- data/lib/mongo_mapper/embedded_document.rb +1 -0
- data/lib/mongo_mapper/plugins.rb +1 -0
- data/lib/mongo_mapper/plugins/associations.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/base.rb +5 -4
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +1 -0
- data/lib/mongo_mapper/plugins/clone.rb +1 -0
- data/lib/mongo_mapper/plugins/descendants.rb +1 -0
- data/lib/mongo_mapper/plugins/dirty.rb +1 -0
- data/lib/mongo_mapper/plugins/equality.rb +4 -3
- data/lib/mongo_mapper/plugins/identity_map.rb +9 -7
- data/lib/mongo_mapper/plugins/inspect.rb +1 -0
- data/lib/mongo_mapper/plugins/keys.rb +50 -73
- data/lib/mongo_mapper/plugins/keys/key.rb +54 -0
- data/lib/mongo_mapper/plugins/logger.rb +1 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +10 -5
- data/lib/mongo_mapper/plugins/pagination.rb +1 -0
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +4 -3
- data/lib/mongo_mapper/plugins/persistence.rb +1 -0
- data/lib/mongo_mapper/plugins/protected.rb +1 -0
- data/lib/mongo_mapper/plugins/rails.rb +1 -0
- data/lib/mongo_mapper/plugins/serialization.rb +4 -3
- data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
- data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +3 -2
- data/lib/mongo_mapper/query.rb +10 -129
- data/lib/mongo_mapper/support.rb +18 -39
- data/lib/mongo_mapper/support/descendant_appends.rb +1 -0
- data/lib/mongo_mapper/support/find.rb +1 -0
- data/lib/mongo_mapper/version.rb +2 -1
- metadata +32 -134
- data/.gitignore +0 -10
- data/Rakefile +0 -37
- data/mongo_mapper.gemspec +0 -214
- data/mongo_mapper_ign.gemspec +0 -217
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/NOTE_ON_TESTING +0 -1
- data/test/active_model_lint_test.rb +0 -13
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
- data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
- data/test/functional/associations/test_in_array_proxy.rb +0 -325
- data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
- data/test/functional/associations/test_many_documents_proxy.rb +0 -536
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
- data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
- data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
- data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
- data/test/functional/associations/test_one_proxy.rb +0 -196
- data/test/functional/test_associations.rb +0 -44
- data/test/functional/test_binary.rb +0 -27
- data/test/functional/test_callbacks.rb +0 -151
- data/test/functional/test_dirty.rb +0 -163
- data/test/functional/test_document.rb +0 -1219
- data/test/functional/test_embedded_document.rb +0 -210
- data/test/functional/test_identity_map.rb +0 -507
- data/test/functional/test_indexing.rb +0 -44
- data/test/functional/test_logger.rb +0 -20
- data/test/functional/test_modifiers.rb +0 -394
- data/test/functional/test_pagination.rb +0 -93
- data/test/functional/test_protected.rb +0 -163
- data/test/functional/test_string_id_compatibility.rb +0 -67
- data/test/functional/test_timestamps.rb +0 -64
- data/test/functional/test_userstamps.rb +0 -28
- data/test/functional/test_validations.rb +0 -342
- data/test/models.rb +0 -227
- data/test/support/custom_matchers.rb +0 -37
- data/test/support/timing.rb +0 -16
- data/test/test_helper.rb +0 -64
- data/test/unit/associations/test_base.rb +0 -212
- data/test/unit/associations/test_proxy.rb +0 -105
- data/test/unit/serializers/test_json_serializer.rb +0 -202
- data/test/unit/test_descendant_appends.rb +0 -71
- data/test/unit/test_document.rb +0 -225
- data/test/unit/test_dynamic_finder.rb +0 -123
- data/test/unit/test_embedded_document.rb +0 -657
- data/test/unit/test_keys.rb +0 -185
- data/test/unit/test_mongo_mapper.rb +0 -118
- data/test/unit/test_pagination.rb +0 -160
- data/test/unit/test_plugins.rb +0 -50
- data/test/unit/test_query.rb +0 -374
- data/test/unit/test_rails.rb +0 -181
- data/test/unit/test_rails_compatibility.rb +0 -52
- data/test/unit/test_serialization.rb +0 -51
- data/test/unit/test_support.rb +0 -382
- data/test/unit/test_time_zones.rb +0 -39
- data/test/unit/test_validations.rb +0 -544
data/README.rdoc
CHANGED
data/lib/mongo_mapper.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# gem 'mongo', '0.20.1'
|
4
|
-
# gem 'jnunemaker-validatable', '1.8.4'
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Make sure you have the correct versions of the gems (see gemspec) in your load path.
|
5
3
|
require 'set'
|
6
4
|
require 'uri'
|
7
|
-
require '
|
5
|
+
require 'plucky'
|
8
6
|
require 'validatable'
|
9
7
|
require 'active_support/all'
|
10
8
|
|
@@ -71,7 +69,7 @@ module MongoMapper
|
|
71
69
|
def self.config_for_environment(environment)
|
72
70
|
env = config[environment]
|
73
71
|
return env if env['uri'].blank?
|
74
|
-
|
72
|
+
|
75
73
|
uri = URI.parse(env['uri'])
|
76
74
|
raise InvalidScheme.new('must be mongodb') unless uri.scheme == 'mongodb'
|
77
75
|
{
|
@@ -92,8 +90,7 @@ module MongoMapper
|
|
92
90
|
end
|
93
91
|
|
94
92
|
def self.setup(config, environment, options={})
|
95
|
-
|
96
|
-
handle_passenger_forking if using_passenger
|
93
|
+
handle_passenger_forking
|
97
94
|
self.config = config
|
98
95
|
connect(environment, options)
|
99
96
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Document
|
3
4
|
extend Support::DescendantAppends
|
@@ -45,34 +46,31 @@ module MongoMapper
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def find(*args)
|
48
|
-
assert_no_first_last_or_all(args)
|
49
49
|
options = args.extract_options!
|
50
50
|
return nil if args.size == 0
|
51
51
|
|
52
52
|
if args.first.is_a?(Array) || args.size > 1
|
53
53
|
find_some(args, options)
|
54
54
|
else
|
55
|
-
|
55
|
+
query = query(options).update(:_id => args[0])
|
56
|
+
find_one(query.to_hash)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
60
|
def find!(*args)
|
60
|
-
assert_no_first_last_or_all(args)
|
61
61
|
options = args.extract_options!
|
62
62
|
raise DocumentNotFound, "Couldn't find without an ID" if args.size == 0
|
63
63
|
|
64
64
|
if args.first.is_a?(Array) || args.size > 1
|
65
65
|
find_some!(args, options)
|
66
66
|
else
|
67
|
-
|
67
|
+
query = query(options).update(:_id => args[0])
|
68
|
+
find_one(query.to_hash) || raise(DocumentNotFound, "Document match #{options.inspect} does not exist in #{collection.name} collection")
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
72
|
def find_each(options={})
|
72
|
-
|
73
|
-
collection.find(criteria, options).each do |doc|
|
74
|
-
yield load(doc)
|
75
|
-
end
|
73
|
+
query(options).find().each { |doc| yield load(doc) }
|
76
74
|
end
|
77
75
|
|
78
76
|
def find_by_id(id)
|
@@ -93,7 +91,7 @@ module MongoMapper
|
|
93
91
|
|
94
92
|
def last(options={})
|
95
93
|
raise ':order option must be provided when using last' if options[:order].blank?
|
96
|
-
find_one(
|
94
|
+
find_one(query(options).reverse.to_hash)
|
97
95
|
end
|
98
96
|
|
99
97
|
def all(options={})
|
@@ -101,7 +99,7 @@ module MongoMapper
|
|
101
99
|
end
|
102
100
|
|
103
101
|
def count(options={})
|
104
|
-
|
102
|
+
query(options).count
|
105
103
|
end
|
106
104
|
|
107
105
|
def exists?(options={})
|
@@ -126,11 +124,11 @@ module MongoMapper
|
|
126
124
|
end
|
127
125
|
|
128
126
|
def delete(*ids)
|
129
|
-
|
127
|
+
query(:_id => ids.flatten).remove
|
130
128
|
end
|
131
129
|
|
132
130
|
def delete_all(options={})
|
133
|
-
|
131
|
+
query(options).remove
|
134
132
|
end
|
135
133
|
|
136
134
|
def destroy(*ids)
|
@@ -153,6 +151,11 @@ module MongoMapper
|
|
153
151
|
superclass.respond_to?(:keys) && superclass.keys.key?(:_type)
|
154
152
|
end
|
155
153
|
|
154
|
+
# @api private for now
|
155
|
+
def query(options={})
|
156
|
+
Query.new(self, options)
|
157
|
+
end
|
158
|
+
|
156
159
|
private
|
157
160
|
def initialize_each(*docs)
|
158
161
|
instances = []
|
@@ -165,15 +168,9 @@ module MongoMapper
|
|
165
168
|
instances.size == 1 ? instances[0] : instances
|
166
169
|
end
|
167
170
|
|
168
|
-
def assert_no_first_last_or_all(args)
|
169
|
-
if args[0] == :first || args[0] == :last || args[0] == :all
|
170
|
-
raise ArgumentError, "#{self}.find(:#{args}) is no longer supported, use #{self}.#{args} instead."
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
171
|
def find_some(ids, options={})
|
175
|
-
|
176
|
-
find_many(
|
172
|
+
query = query(options).update(:_id => ids.flatten.compact.uniq)
|
173
|
+
find_many(query.to_hash).compact
|
177
174
|
end
|
178
175
|
|
179
176
|
def find_some!(ids, options={})
|
@@ -189,30 +186,12 @@ module MongoMapper
|
|
189
186
|
|
190
187
|
# All query methods that load documents pass through find_one or find_many
|
191
188
|
def find_one(options={})
|
192
|
-
|
193
|
-
if doc = collection.find_one(criteria, options)
|
194
|
-
load(doc)
|
195
|
-
end
|
189
|
+
load(query(options).first)
|
196
190
|
end
|
197
191
|
|
198
192
|
# All query methods that load documents pass through find_one or find_many
|
199
193
|
def find_many(options)
|
200
|
-
|
201
|
-
collection.find(criteria, options).to_a.map do |doc|
|
202
|
-
load(doc)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def invert_order_clause(order)
|
207
|
-
order.split(',').map do |order_segment|
|
208
|
-
if order_segment =~ /\sasc/i
|
209
|
-
order_segment.sub /\sasc/i, ' desc'
|
210
|
-
elsif order_segment =~ /\sdesc/i
|
211
|
-
order_segment.sub /\sdesc/i, ' asc'
|
212
|
-
else
|
213
|
-
"#{order_segment.strip} desc"
|
214
|
-
end
|
215
|
-
end.join(',')
|
194
|
+
query(options).all().map { |doc| load(doc) }
|
216
195
|
end
|
217
196
|
|
218
197
|
def update_single(id, attrs)
|
@@ -220,9 +199,9 @@ module MongoMapper
|
|
220
199
|
raise ArgumentError, "Updating a single document requires an id and a hash of attributes"
|
221
200
|
end
|
222
201
|
|
223
|
-
|
224
|
-
|
225
|
-
|
202
|
+
find(id).tap do |doc|
|
203
|
+
doc.update_attributes(attrs)
|
204
|
+
end
|
226
205
|
end
|
227
206
|
|
228
207
|
def update_multiple(docs)
|
@@ -234,14 +213,6 @@ module MongoMapper
|
|
234
213
|
docs.each_pair { |id, attrs| instances << update(id, attrs) }
|
235
214
|
instances
|
236
215
|
end
|
237
|
-
|
238
|
-
def to_criteria(options={})
|
239
|
-
Query.new(self, options).criteria
|
240
|
-
end
|
241
|
-
|
242
|
-
def to_query(options={})
|
243
|
-
Query.new(self, options).to_a
|
244
|
-
end
|
245
216
|
end
|
246
217
|
|
247
218
|
module InstanceMethods
|
@@ -274,9 +245,9 @@ module MongoMapper
|
|
274
245
|
end
|
275
246
|
|
276
247
|
def reload
|
277
|
-
if
|
248
|
+
if doc = self.class.query(:_id => id).first
|
278
249
|
self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) }
|
279
|
-
self.attributes =
|
250
|
+
self.attributes = doc
|
280
251
|
self
|
281
252
|
else
|
282
253
|
raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
|
data/lib/mongo_mapper/plugins.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module Associations
|
@@ -16,8 +17,8 @@ module MongoMapper
|
|
16
17
|
|
17
18
|
def class_name
|
18
19
|
return @class_name if defined?(@class_name)
|
19
|
-
|
20
|
-
@class_name =
|
20
|
+
|
21
|
+
@class_name =
|
21
22
|
if cn = options[:class_name]
|
22
23
|
cn
|
23
24
|
elsif many?
|
@@ -78,8 +79,8 @@ module MongoMapper
|
|
78
79
|
# hate this, need to revisit
|
79
80
|
def proxy_class
|
80
81
|
return @proxy_class if defined?(@proxy_class)
|
81
|
-
|
82
|
-
@proxy_class =
|
82
|
+
|
83
|
+
@proxy_class =
|
83
84
|
if many?
|
84
85
|
if klass.embeddable?
|
85
86
|
polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module Equality
|
@@ -5,15 +6,15 @@ module MongoMapper
|
|
5
6
|
def ==(other)
|
6
7
|
other.is_a?(self.class) && _id == other._id
|
7
8
|
end
|
8
|
-
|
9
|
+
|
9
10
|
def eql?(other)
|
10
11
|
self == other
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
def equal?(other)
|
14
15
|
object_id === other.object_id
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def hash
|
18
19
|
_id.hash
|
19
20
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module IdentityMap
|
@@ -8,7 +9,7 @@ module MongoMapper
|
|
8
9
|
def self.clear
|
9
10
|
models.each { |m| m.identity_map.clear }
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
def self.configure(model)
|
13
14
|
IdentityMap.models << model
|
14
15
|
end
|
@@ -28,27 +29,28 @@ module MongoMapper
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def find_one(options={})
|
31
|
-
|
32
|
-
|
32
|
+
query = query(options)
|
33
|
+
criteria = query.criteria.to_hash
|
34
|
+
|
33
35
|
if simple_find?(criteria) && identity_map.key?(criteria[:_id])
|
34
36
|
identity_map[criteria[:_id]]
|
35
37
|
else
|
36
38
|
super.tap do |document|
|
37
|
-
remove_documents_from_map(document) if selecting_fields?(
|
39
|
+
remove_documents_from_map(document) if selecting_fields?(query.options)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def find_many(options)
|
43
|
-
criteria, query_options = to_query(options)
|
44
45
|
super.tap do |documents|
|
45
|
-
remove_documents_from_map(documents) if selecting_fields?(
|
46
|
+
remove_documents_from_map(documents) if selecting_fields?(query(options).options)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
50
|
def load(attrs)
|
51
|
+
return nil if attrs.nil?
|
50
52
|
document = identity_map[attrs['_id']]
|
51
|
-
|
53
|
+
|
52
54
|
if document.nil? || identity_map_off?
|
53
55
|
document = super
|
54
56
|
identity_map[document._id] = document if identity_map_on?
|