mongoid 5.0.1 → 5.0.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +2 -0
- data/README.md +0 -1
- data/lib/mongoid.rb +0 -7
- data/lib/mongoid/attributes.rb +2 -1
- data/lib/mongoid/attributes/nested.rb +3 -0
- data/lib/mongoid/clients.rb +0 -6
- data/lib/mongoid/clients/options.rb +0 -6
- data/lib/mongoid/clients/storage_options.rb +0 -3
- data/lib/mongoid/clients/thread_options.rb +0 -3
- data/lib/mongoid/config.rb +0 -7
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/mongo.rb +2 -2
- data/lib/mongoid/criteria.rb +6 -1
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/indexable.rb +7 -5
- data/lib/mongoid/indexable/specification.rb +14 -0
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/persistable/settable.rb +8 -1
- data/lib/mongoid/query_cache.rb +14 -4
- data/lib/mongoid/railtie.rb +1 -0
- data/lib/mongoid/relations/accessors.rb +3 -1
- data/lib/mongoid/relations/embedded/batchable.rb +5 -1
- data/lib/mongoid/relations/metadata.rb +3 -0
- data/lib/mongoid/tasks/database.rb +1 -1
- data/lib/mongoid/threaded.rb +0 -5
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/bomb.rb +4 -0
- data/spec/app/models/building.rb +2 -1
- data/spec/app/models/building_address.rb +3 -1
- data/spec/app/models/courier_job.rb +4 -0
- data/spec/app/models/explosion.rb +4 -0
- data/spec/app/models/message.rb +3 -0
- data/spec/app/models/name.rb +1 -0
- data/spec/app/models/post.rb +3 -0
- data/spec/app/models/sandwich.rb +5 -0
- data/spec/app/models/shipment_address.rb +2 -0
- data/spec/mongoid/attributes/nested_spec.rb +77 -18
- data/spec/mongoid/attributes_spec.rb +13 -0
- data/spec/mongoid/criteria_spec.rb +52 -0
- data/spec/mongoid/document_spec.rb +37 -13
- data/spec/mongoid/indexable/specification_spec.rb +25 -0
- data/spec/mongoid/persistable_spec.rb +17 -0
- data/spec/mongoid/query_cache_spec.rb +51 -2
- data/spec/mongoid/relations/accessors_spec.rb +69 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +63 -0
- data/spec/mongoid/relations/embedded/one_spec.rb +45 -0
- data/spec/mongoid/relations/metadata_spec.rb +16 -0
- data/spec/mongoid/relations/referenced/one_spec.rb +24 -0
- data/spec/mongoid/tasks/database_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -8
- metadata +10 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa194434a7d5ebe53a1f05929202d4976201f90
|
4
|
+
data.tar.gz: 31e2605c59062cb947a510d399a25c173c9ff504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d133d4ce0e944995f0a0718ba506ca8ede6cc6f232a14cbe34d371f3db80d5736610ffdc6726bb5de3b658355c4ce818b10c82c172669da82aeafabbb13172
|
7
|
+
data.tar.gz: bf1274305b4c8165ac084e06246adf841fd17aeefdf017eb442e81d92c2aa75c6ab8183e591ba7e5b8a757d8ea39899c4a6ce41cb966d835f020edf3a45e6e6e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Mongoid
|
2
2
|
[](https://travis-ci.org/mongodb/mongoid)
|
3
3
|
[](https://codeclimate.com/github/mongodb/mongoid)
|
4
|
-
[](https://coveralls.io/r/mongodb/mongoid?branch=master)
|
5
4
|
[](https://www.versioneye.com/ruby/mongoid/4.0.0)
|
6
5
|
|
7
6
|
Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
data/lib/mongoid.rb
CHANGED
@@ -34,7 +34,6 @@ I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml
|
|
34
34
|
|
35
35
|
module Mongoid
|
36
36
|
extend Loggable
|
37
|
-
extend Gem::Deprecate
|
38
37
|
extend self
|
39
38
|
|
40
39
|
# The minimum MongoDB version supported.
|
@@ -65,8 +64,6 @@ module Mongoid
|
|
65
64
|
def default_client
|
66
65
|
Clients.default
|
67
66
|
end
|
68
|
-
alias :default_session :default_client
|
69
|
-
deprecate :default_session, :default_client, 2015, 12
|
70
67
|
|
71
68
|
# Disconnect all active clients.
|
72
69
|
#
|
@@ -79,8 +76,6 @@ module Mongoid
|
|
79
76
|
def disconnect_clients
|
80
77
|
Clients.disconnect
|
81
78
|
end
|
82
|
-
alias :disconnect_sessions :disconnect_clients
|
83
|
-
deprecate :disconnect_sessions, :disconnect_clients, 2015, 12
|
84
79
|
|
85
80
|
# Convenience method for getting a named client.
|
86
81
|
#
|
@@ -93,8 +88,6 @@ module Mongoid
|
|
93
88
|
def client(name)
|
94
89
|
Clients.with_name(name)
|
95
90
|
end
|
96
|
-
alias :session :client
|
97
|
-
deprecate :session, :client, 2015, 12
|
98
91
|
|
99
92
|
# Take all the public instance methods from the Config singleton and allow
|
100
93
|
# them to be accessed through the Mongoid module directly.
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -176,7 +176,8 @@ module Mongoid
|
|
176
176
|
attribute_will_change!(access)
|
177
177
|
end
|
178
178
|
if localized
|
179
|
-
|
179
|
+
attributes[access] ||= {}
|
180
|
+
attributes[access].merge!(typed_value)
|
180
181
|
else
|
181
182
|
attributes[access] = typed_value
|
182
183
|
end
|
@@ -53,6 +53,9 @@ module Mongoid
|
|
53
53
|
autosave_nested_attributes(metadata)
|
54
54
|
re_define_method(meth) do |attrs|
|
55
55
|
_assigning do
|
56
|
+
if metadata.polymorphic? and metadata.inverse_type
|
57
|
+
options = options.merge!(:class_name => self.send(metadata.inverse_type))
|
58
|
+
end
|
56
59
|
metadata.nested_builder(attrs, options).build(self)
|
57
60
|
end
|
58
61
|
end
|
data/lib/mongoid/clients.rb
CHANGED
@@ -8,7 +8,6 @@ require "mongoid/clients/options"
|
|
8
8
|
module Mongoid
|
9
9
|
module Clients
|
10
10
|
extend ActiveSupport::Concern
|
11
|
-
extend Gem::Deprecate
|
12
11
|
include StorageOptions
|
13
12
|
include ThreadOptions
|
14
13
|
include Options
|
@@ -93,15 +92,12 @@ module Mongoid
|
|
93
92
|
def mongo_client
|
94
93
|
super || self.class.mongo_client
|
95
94
|
end
|
96
|
-
alias :mongo_session :mongo_client
|
97
|
-
deprecate :mongo_session, :mongo_client, 2015, 12
|
98
95
|
|
99
96
|
def collection_name
|
100
97
|
super || self.class.collection_name
|
101
98
|
end
|
102
99
|
|
103
100
|
module ClassMethods
|
104
|
-
extend Gem::Deprecate
|
105
101
|
|
106
102
|
# Get the client for this model. This is determined in the following order:
|
107
103
|
#
|
@@ -123,8 +119,6 @@ module Mongoid
|
|
123
119
|
opts.merge!(database: database_name) unless client.database.name.to_sym == database_name.to_sym
|
124
120
|
client.with(opts)
|
125
121
|
end
|
126
|
-
alias :mongo_session :mongo_client
|
127
|
-
deprecate :mongo_session, :mongo_client, 2015, 12
|
128
122
|
|
129
123
|
# Get the collection for this model from the client. Will check for an
|
130
124
|
# overridden collection name from the store_in macro or the collection
|
@@ -3,7 +3,6 @@ module Mongoid
|
|
3
3
|
module Clients
|
4
4
|
module Options
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
extend Gem::Deprecate
|
7
6
|
|
8
7
|
# Tell the next persistence operation to store in a specific collection,
|
9
8
|
# database or client.
|
@@ -54,8 +53,6 @@ module Mongoid
|
|
54
53
|
client.with(persistence_options.reject{ |k, v| k == :collection || k == :client })
|
55
54
|
end
|
56
55
|
end
|
57
|
-
alias :mongo_session :mongo_client
|
58
|
-
deprecate :mongo_session, :mongo_client, 2015, 12
|
59
56
|
|
60
57
|
def collection_name
|
61
58
|
if persistence_options && v = persistence_options[:collection]
|
@@ -99,7 +96,6 @@ module Mongoid
|
|
99
96
|
end
|
100
97
|
|
101
98
|
module ClassMethods
|
102
|
-
extend Gem::Deprecate
|
103
99
|
include Threaded
|
104
100
|
|
105
101
|
def client_name
|
@@ -108,8 +104,6 @@ module Mongoid
|
|
108
104
|
end
|
109
105
|
super
|
110
106
|
end
|
111
|
-
alias :session_name :client_name
|
112
|
-
deprecate :session_name, :client_name, 2015, 12
|
113
107
|
|
114
108
|
def collection_name
|
115
109
|
if persistence_options && v = persistence_options[:collection]
|
@@ -12,7 +12,6 @@ module Mongoid
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
-
extend Gem::Deprecate
|
16
15
|
|
17
16
|
# Give this model specific custom default storage options.
|
18
17
|
#
|
@@ -103,8 +102,6 @@ module Mongoid
|
|
103
102
|
def client_name
|
104
103
|
__evaluate__(storage_options[:client])
|
105
104
|
end
|
106
|
-
alias :session_name :client_name
|
107
|
-
deprecate :session_name, :client_name, 2015, 12
|
108
105
|
|
109
106
|
# Get the database name for the model.
|
110
107
|
#
|
@@ -5,13 +5,10 @@ module Mongoid
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
extend Gem::Deprecate
|
9
8
|
|
10
9
|
def client_name
|
11
10
|
Threaded.client_override || super
|
12
11
|
end
|
13
|
-
alias :session_name :client_name
|
14
|
-
deprecate :session_name, :client_name, 2015, 12
|
15
12
|
|
16
13
|
def database_name
|
17
14
|
Threaded.database_override || super
|
data/lib/mongoid/config.rb
CHANGED
@@ -8,7 +8,6 @@ module Mongoid
|
|
8
8
|
# This module defines all the configuration options for Mongoid, including the
|
9
9
|
# database connections.
|
10
10
|
module Config
|
11
|
-
extend Gem::Deprecate
|
12
11
|
extend self
|
13
12
|
extend Options
|
14
13
|
|
@@ -158,8 +157,6 @@ module Mongoid
|
|
158
157
|
def override_client(name)
|
159
158
|
Threaded.client_override = name ? name.to_s : nil
|
160
159
|
end
|
161
|
-
alias :override_session :override_client
|
162
|
-
deprecate :override_session, :override_client, 2015, 12
|
163
160
|
|
164
161
|
# Purge all data in all collections, including indexes.
|
165
162
|
#
|
@@ -219,8 +216,6 @@ module Mongoid
|
|
219
216
|
def clients
|
220
217
|
@clients ||= {}
|
221
218
|
end
|
222
|
-
alias :sessions :clients
|
223
|
-
deprecate :sessions, :clients, 2015, 12
|
224
219
|
|
225
220
|
# Get the time zone to use.
|
226
221
|
#
|
@@ -254,7 +249,5 @@ module Mongoid
|
|
254
249
|
Validators::Client.validate(c)
|
255
250
|
@clients = c
|
256
251
|
end
|
257
|
-
alias :sessions= :clients=
|
258
|
-
deprecate :sessions=, :clients=, 2015, 12
|
259
252
|
end
|
260
253
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
module Mongoid
|
3
3
|
module Contextual
|
4
4
|
module Command
|
5
|
-
extend Gem::Deprecate
|
6
5
|
|
7
6
|
# @attribute [r] collection The collection to query against.
|
8
7
|
# @attribute [r] criteria The criteria for the context.
|
@@ -31,8 +30,6 @@ module Mongoid
|
|
31
30
|
def client
|
32
31
|
collection.database.client
|
33
32
|
end
|
34
|
-
alias :session :client
|
35
|
-
deprecate :session, :client, 2015, 12
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -237,7 +237,7 @@ module Mongoid
|
|
237
237
|
def first
|
238
238
|
return documents.first if cached? && cache_loaded?
|
239
239
|
try_cache(:first) do
|
240
|
-
with_eager_loading(view.first)
|
240
|
+
with_eager_loading(view.limit(-1).first)
|
241
241
|
end
|
242
242
|
end
|
243
243
|
alias :one :first
|
@@ -335,7 +335,7 @@ module Mongoid
|
|
335
335
|
def last
|
336
336
|
try_cache(:last) do
|
337
337
|
with_inverse_sorting do
|
338
|
-
with_eager_loading(view.first)
|
338
|
+
with_eager_loading(view.limit(-1).first)
|
339
339
|
end
|
340
340
|
end
|
341
341
|
end
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -597,7 +597,12 @@ module Mongoid
|
|
597
597
|
#
|
598
598
|
# @since 3.0.3
|
599
599
|
def type_selection
|
600
|
-
|
600
|
+
klasses = klass._types
|
601
|
+
if klasses.size > 1
|
602
|
+
{ _type: { "$in" => klass._types }}
|
603
|
+
else
|
604
|
+
{ _type: klass._types[0] }
|
605
|
+
end
|
601
606
|
end
|
602
607
|
|
603
608
|
# Get a new selector with type selection in it.
|
@@ -198,7 +198,7 @@ module Mongoid
|
|
198
198
|
# @since 3.0.0
|
199
199
|
def mongoize(object)
|
200
200
|
return if object.nil?
|
201
|
-
evolve(object).update_values { |value| value.mongoize }
|
201
|
+
evolve(object.dup).update_values { |value| value.mongoize }
|
202
202
|
end
|
203
203
|
|
204
204
|
# Can the size of this object change?
|
data/lib/mongoid/indexable.rb
CHANGED
@@ -31,10 +31,10 @@ module Mongoid
|
|
31
31
|
index_specifications.each do |spec|
|
32
32
|
key, options = spec.key, spec.options
|
33
33
|
if database = options[:database]
|
34
|
-
with(
|
34
|
+
with(database: database).
|
35
35
|
collection.indexes.create_one(key, options.except(:database))
|
36
36
|
else
|
37
|
-
|
37
|
+
collection.indexes.create_one(key, options)
|
38
38
|
end
|
39
39
|
end and true
|
40
40
|
end
|
@@ -50,7 +50,7 @@ module Mongoid
|
|
50
50
|
# @since 3.0.0
|
51
51
|
def remove_indexes
|
52
52
|
indexed_database_names.each do |database|
|
53
|
-
collection = with(
|
53
|
+
collection = with(database: database).collection
|
54
54
|
begin
|
55
55
|
collection.indexes.each do |spec|
|
56
56
|
unless spec["name"] == "_id_"
|
@@ -113,9 +113,11 @@ module Mongoid
|
|
113
113
|
# @return [ Specification ] The found specification.
|
114
114
|
#
|
115
115
|
# @since 4.0.0
|
116
|
-
def index_specification(index_hash)
|
116
|
+
def index_specification(index_hash, index_name = nil)
|
117
117
|
index = OpenStruct.new(fields: index_hash.keys, key: index_hash)
|
118
|
-
index_specifications.detect
|
118
|
+
index_specifications.detect do |spec|
|
119
|
+
spec == index || (index_name && index_name == spec.name)
|
120
|
+
end
|
119
121
|
end
|
120
122
|
|
121
123
|
private
|
@@ -56,6 +56,20 @@ module Mongoid
|
|
56
56
|
@options = normalize_options(options.dup)
|
57
57
|
end
|
58
58
|
|
59
|
+
# Get the index name, generated using the index key.
|
60
|
+
#
|
61
|
+
# @example Get the index name.
|
62
|
+
# specification.name
|
63
|
+
#
|
64
|
+
# @return [ String ] name The index name.
|
65
|
+
#
|
66
|
+
# @since 5.0.2
|
67
|
+
def name
|
68
|
+
@name ||= key.reduce([]) do |n, (k,v)|
|
69
|
+
n << "#{k}_#{v}"
|
70
|
+
end.join('_')
|
71
|
+
end
|
72
|
+
|
59
73
|
private
|
60
74
|
|
61
75
|
# Normalize the spec, in case aliased fields are provided.
|
@@ -22,12 +22,19 @@ module Mongoid
|
|
22
22
|
def set(setters)
|
23
23
|
prepare_atomic_operation do |ops|
|
24
24
|
process_atomic_operations(setters) do |field, value|
|
25
|
-
|
25
|
+
field_and_value_hash = hasherizer(field.split('.'), value)
|
26
|
+
field = field_and_value_hash.keys.first
|
27
|
+
process_attribute(field, field_and_value_hash[field])
|
26
28
|
ops[atomic_attribute_name(field)] = attributes[field]
|
27
29
|
end
|
28
30
|
{ "$set" => ops }
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
def hasherizer(keys, value)
|
36
|
+
return value if keys.empty?
|
37
|
+
{}.tap { |hash| hash[keys.shift] = hasherizer(keys, value) }
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/mongoid/query_cache.rb
CHANGED
@@ -206,12 +206,10 @@ module Mongoid
|
|
206
206
|
if system_collection? || !QueryCache.enabled?
|
207
207
|
super
|
208
208
|
else
|
209
|
-
|
210
|
-
cursor = QueryCache.cache_table[key]
|
211
|
-
unless cursor
|
209
|
+
unless cursor = cached_cursor
|
212
210
|
server = read.select_server(cluster)
|
213
211
|
cursor = CachedCursor.new(view, send_initial_query(server), server)
|
214
|
-
QueryCache.cache_table[
|
212
|
+
QueryCache.cache_table[cache_key] = cursor
|
215
213
|
end
|
216
214
|
cursor.each do |doc|
|
217
215
|
yield doc
|
@@ -222,6 +220,18 @@ module Mongoid
|
|
222
220
|
|
223
221
|
private
|
224
222
|
|
223
|
+
def cached_cursor
|
224
|
+
if limit
|
225
|
+
key = [ collection.namespace, selector, nil, skip, projection ]
|
226
|
+
cursor = QueryCache.cache_table[key]
|
227
|
+
if cursor
|
228
|
+
limited_docs = cursor.to_a[0...limit.abs]
|
229
|
+
cursor.instance_variable_set(:@cached_documents, limited_docs)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
cursor || QueryCache.cache_table[cache_key]
|
233
|
+
end
|
234
|
+
|
225
235
|
def cache_key
|
226
236
|
[ collection.namespace, selector, limit, skip, projection ]
|
227
237
|
end
|
data/lib/mongoid/railtie.rb
CHANGED
@@ -77,6 +77,7 @@ module Rails
|
|
77
77
|
unless config.action_dispatch.rescue_responses
|
78
78
|
ActionDispatch::ShowExceptions.rescue_responses.update(Railtie.rescue_responses)
|
79
79
|
end
|
80
|
+
Mongo::Logger.logger = ::Mongoid.logger
|
80
81
|
end
|
81
82
|
|
82
83
|
# Due to all models not getting loaded and messing up inheritance queries
|
@@ -228,7 +228,9 @@ module Mongoid
|
|
228
228
|
re_define_method("#{name}=") do |object|
|
229
229
|
without_autobuild do
|
230
230
|
if value = get_relation(name, metadata, object)
|
231
|
-
|
231
|
+
if value.respond_to?(:substitute)
|
232
|
+
set_relation(name, value.substitute(object.substitutable))
|
233
|
+
end
|
232
234
|
else
|
233
235
|
__build__(name, object.substitutable, metadata)
|
234
236
|
end
|
@@ -79,8 +79,12 @@ module Mongoid
|
|
79
79
|
if docs.blank?
|
80
80
|
if _assigning? && !empty?
|
81
81
|
base.add_atomic_unset(first)
|
82
|
+
target_duplicate = target.dup
|
83
|
+
pre_process_batch_remove(target_duplicate, :delete)
|
84
|
+
post_process_batch_remove(target_duplicate, :delete)
|
85
|
+
else
|
86
|
+
batch_remove(target.dup)
|
82
87
|
end
|
83
|
-
batch_remove(target.dup)
|
84
88
|
else
|
85
89
|
base.delayed_atomic_sets.clear unless _assigning?
|
86
90
|
docs = normalize_docs(docs).compact
|
@@ -663,6 +663,9 @@ module Mongoid
|
|
663
663
|
#
|
664
664
|
# @since 2.0.0.rc.1
|
665
665
|
def nested_builder(attributes, options)
|
666
|
+
if polymorphic? && options[:class_name]
|
667
|
+
self[:class_name] = options[:class_name]
|
668
|
+
end
|
666
669
|
relation.nested_builder(self, attributes, options)
|
667
670
|
end
|
668
671
|
|