mongoid 8.0.1 → 8.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/config/locales/en.yml +1 -0
  4. data/lib/mongoid/association/accessors.rb +6 -6
  5. data/lib/mongoid/association/bindable.rb +2 -2
  6. data/lib/mongoid/association/constrainable.rb +0 -1
  7. data/lib/mongoid/association/embedded/batchable.rb +5 -5
  8. data/lib/mongoid/association/embedded/cyclic.rb +1 -1
  9. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -2
  10. data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
  11. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -10
  12. data/lib/mongoid/association/embedded/embeds_many.rb +2 -2
  13. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
  14. data/lib/mongoid/association/embedded/embeds_one.rb +3 -3
  15. data/lib/mongoid/association/many.rb +6 -7
  16. data/lib/mongoid/association/nested/many.rb +3 -3
  17. data/lib/mongoid/association/nested/nested_buildable.rb +4 -4
  18. data/lib/mongoid/association/nested/one.rb +5 -5
  19. data/lib/mongoid/association/one.rb +2 -2
  20. data/lib/mongoid/association/options.rb +9 -9
  21. data/lib/mongoid/association/proxy.rb +2 -3
  22. data/lib/mongoid/association/referenced/auto_save.rb +1 -1
  23. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -6
  24. data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
  25. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  26. data/lib/mongoid/association/referenced/eager.rb +2 -2
  27. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +2 -2
  28. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +2 -2
  29. data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -10
  30. data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
  31. data/lib/mongoid/association/referenced/has_many.rb +3 -3
  32. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +5 -5
  33. data/lib/mongoid/association/referenced/has_one/proxy.rb +1 -1
  34. data/lib/mongoid/association/referenced/has_one.rb +3 -3
  35. data/lib/mongoid/association/referenced/syncable.rb +2 -2
  36. data/lib/mongoid/association/reflections.rb +2 -2
  37. data/lib/mongoid/association/relatable.rb +6 -6
  38. data/lib/mongoid/association.rb +5 -5
  39. data/lib/mongoid/atomic/modifiers.rb +2 -2
  40. data/lib/mongoid/attributes/dynamic.rb +3 -3
  41. data/lib/mongoid/attributes/nested.rb +5 -5
  42. data/lib/mongoid/attributes/processing.rb +1 -1
  43. data/lib/mongoid/attributes/projector.rb +1 -1
  44. data/lib/mongoid/attributes/readonly.rb +2 -2
  45. data/lib/mongoid/attributes.rb +13 -13
  46. data/lib/mongoid/cacheable.rb +2 -2
  47. data/lib/mongoid/changeable.rb +5 -5
  48. data/lib/mongoid/clients/options.rb +1 -1
  49. data/lib/mongoid/clients/validators/storage.rb +3 -3
  50. data/lib/mongoid/config/validators/client.rb +6 -6
  51. data/lib/mongoid/config.rb +7 -7
  52. data/lib/mongoid/contextual/aggregable/memory.rb +1 -1
  53. data/lib/mongoid/contextual/aggregable/mongo.rb +4 -4
  54. data/lib/mongoid/contextual/aggregable/none.rb +1 -1
  55. data/lib/mongoid/contextual/atomic.rb +1 -1
  56. data/lib/mongoid/contextual/geo_near.rb +7 -7
  57. data/lib/mongoid/contextual/memory.rb +5 -5
  58. data/lib/mongoid/contextual/mongo.rb +14 -14
  59. data/lib/mongoid/contextual/none.rb +2 -2
  60. data/lib/mongoid/contextual/queryable.rb +1 -1
  61. data/lib/mongoid/contextual.rb +2 -2
  62. data/lib/mongoid/criteria/findable.rb +7 -4
  63. data/lib/mongoid/criteria/includable.rb +1 -1
  64. data/lib/mongoid/criteria/permission.rb +1 -1
  65. data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
  66. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  67. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +2 -2
  68. data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
  69. data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -3
  70. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +1 -1
  71. data/lib/mongoid/criteria/queryable/key.rb +3 -3
  72. data/lib/mongoid/criteria/queryable/optional.rb +2 -2
  73. data/lib/mongoid/criteria/queryable/options.rb +1 -1
  74. data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
  75. data/lib/mongoid/criteria/queryable/selectable.rb +3 -3
  76. data/lib/mongoid/criteria/queryable/selector.rb +3 -3
  77. data/lib/mongoid/criteria/queryable/smash.rb +1 -1
  78. data/lib/mongoid/criteria/queryable.rb +1 -1
  79. data/lib/mongoid/criteria/scopable.rb +2 -2
  80. data/lib/mongoid/criteria.rb +14 -9
  81. data/lib/mongoid/deprecable.rb +1 -1
  82. data/lib/mongoid/document.rb +2 -2
  83. data/lib/mongoid/equality.rb +12 -12
  84. data/lib/mongoid/errors/document_not_found.rb +5 -5
  85. data/lib/mongoid/errors/invalid_config_option.rb +1 -1
  86. data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
  87. data/lib/mongoid/errors/invalid_field.rb +1 -1
  88. data/lib/mongoid/errors/invalid_relation.rb +1 -1
  89. data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
  90. data/lib/mongoid/errors/invalid_session_use.rb +1 -1
  91. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  92. data/lib/mongoid/errors/mongoid_error.rb +3 -3
  93. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
  94. data/lib/mongoid/errors/no_client_database.rb +1 -1
  95. data/lib/mongoid/errors/no_client_hosts.rb +1 -1
  96. data/lib/mongoid/errors/readonly_attribute.rb +1 -1
  97. data/lib/mongoid/errors/unknown_attribute.rb +1 -1
  98. data/lib/mongoid/extensions/array.rb +1 -1
  99. data/lib/mongoid/extensions/big_decimal.rb +4 -0
  100. data/lib/mongoid/extensions/false_class.rb +1 -1
  101. data/lib/mongoid/extensions/float.rb +6 -2
  102. data/lib/mongoid/extensions/hash.rb +1 -1
  103. data/lib/mongoid/extensions/integer.rb +6 -2
  104. data/lib/mongoid/extensions/module.rb +1 -1
  105. data/lib/mongoid/extensions/object.rb +6 -6
  106. data/lib/mongoid/extensions/string.rb +9 -9
  107. data/lib/mongoid/extensions/symbol.rb +1 -1
  108. data/lib/mongoid/extensions/true_class.rb +1 -1
  109. data/lib/mongoid/fields/foreign_key.rb +4 -4
  110. data/lib/mongoid/fields/localized.rb +9 -4
  111. data/lib/mongoid/fields/standard.rb +7 -7
  112. data/lib/mongoid/fields.rb +9 -9
  113. data/lib/mongoid/findable.rb +7 -6
  114. data/lib/mongoid/indexable/specification.rb +1 -1
  115. data/lib/mongoid/indexable/validators/options.rb +2 -1
  116. data/lib/mongoid/interceptable.rb +4 -4
  117. data/lib/mongoid/matchable.rb +1 -1
  118. data/lib/mongoid/matcher.rb +12 -7
  119. data/lib/mongoid/persistable/creatable.rb +4 -4
  120. data/lib/mongoid/persistable/deletable.rb +1 -1
  121. data/lib/mongoid/persistable/destroyable.rb +1 -1
  122. data/lib/mongoid/persistable/savable.rb +2 -2
  123. data/lib/mongoid/persistable/unsettable.rb +1 -1
  124. data/lib/mongoid/persistable/updatable.rb +7 -7
  125. data/lib/mongoid/persistable/upsertable.rb +1 -1
  126. data/lib/mongoid/persistable.rb +3 -3
  127. data/lib/mongoid/persistence_context.rb +44 -8
  128. data/lib/mongoid/query_cache.rb +2 -2
  129. data/lib/mongoid/scopable.rb +26 -22
  130. data/lib/mongoid/serializable.rb +10 -6
  131. data/lib/mongoid/stateful.rb +10 -10
  132. data/lib/mongoid/tasks/database.rb +0 -2
  133. data/lib/mongoid/threaded/lifecycle.rb +5 -5
  134. data/lib/mongoid/threaded.rb +12 -12
  135. data/lib/mongoid/timestamps/updated.rb +1 -1
  136. data/lib/mongoid/traversable.rb +3 -3
  137. data/lib/mongoid/validatable/localizable.rb +1 -1
  138. data/lib/mongoid/validatable/macros.rb +0 -2
  139. data/lib/mongoid/validatable/presence.rb +2 -2
  140. data/lib/mongoid/validatable/uniqueness.rb +7 -7
  141. data/lib/mongoid/validatable.rb +6 -6
  142. data/lib/mongoid/version.rb +1 -1
  143. data/spec/integration/i18n_fallbacks_spec.rb +1 -17
  144. data/spec/mongoid/cacheable_spec.rb +3 -3
  145. data/spec/mongoid/clients_spec.rb +25 -0
  146. data/spec/mongoid/contextual/memory_spec.rb +4 -5
  147. data/spec/mongoid/contextual/mongo_spec.rb +2 -4
  148. data/spec/mongoid/criteria_projection_spec.rb +0 -1
  149. data/spec/mongoid/criteria_spec.rb +1 -1
  150. data/spec/mongoid/equality_spec.rb +12 -12
  151. data/spec/mongoid/extensions/big_decimal_spec.rb +15 -0
  152. data/spec/mongoid/extensions/float_spec.rb +10 -3
  153. data/spec/mongoid/extensions/integer_spec.rb +10 -3
  154. data/spec/mongoid/fields/localized_spec.rb +37 -12
  155. data/spec/mongoid/indexable_spec.rb +23 -1
  156. data/spec/mongoid/scopable_spec.rb +34 -16
  157. data/spec/mongoid/validatable/uniqueness_spec.rb +0 -1
  158. data/spec/support/macros.rb +16 -0
  159. data.tar.gz.sig +0 -0
  160. metadata +643 -643
  161. metadata.gz.sig +0 -0
@@ -13,13 +13,13 @@ module Mongoid
13
13
  # @example Update the attribute.
14
14
  # person.update_attribute(:title, "Sir")
15
15
  #
16
- # @param [ Symbol, String ] name The name of the attribute.
16
+ # @param [ Symbol | String ] name The name of the attribute.
17
17
  # @param [ Object ] value The new value of the attribute.a
18
18
  #
19
19
  # @raise [ Errors::ReadonlyAttribute ] If the field cannot be changed due
20
20
  # to being flagged as read-only.
21
21
  #
22
- # @return [ true, false ] True if save was successful, false if not.
22
+ # @return [ true | false ] True if save was successful, false if not.
23
23
  def update_attribute(name, value)
24
24
  as_writable_attribute!(name, value) do |access|
25
25
  normalized = name.to_s
@@ -35,7 +35,7 @@ module Mongoid
35
35
  #
36
36
  # @param [ Hash ] attributes The attributes to update.
37
37
  #
38
- # @return [ true, false ] True if validation passed, false if not.
38
+ # @return [ true | false ] True if validation passed, false if not.
39
39
  def update(attributes = {})
40
40
  assign_attributes(attributes)
41
41
  save
@@ -53,7 +53,7 @@ module Mongoid
53
53
  # @raise [ Errors::Validations ] If validation failed.
54
54
  # @raise [ Errors::Callbacks ] If a callback returns false.
55
55
  #
56
- # @return [ true, false ] True if validation passed.
56
+ # @return [ true | false ] True if validation passed.
57
57
  def update!(attributes = {})
58
58
  result = update_attributes(attributes)
59
59
  unless result
@@ -91,7 +91,7 @@ module Mongoid
91
91
  #
92
92
  # @param [ Hash ] options The options.
93
93
  #
94
- # @return [ true, false ] The result of the update.
94
+ # @return [ true | false ] The result of the update.
95
95
  def prepare_update(options = {})
96
96
  return false if performing_validations?(options) &&
97
97
  invalid?(options[:context] || :update)
@@ -119,9 +119,9 @@ module Mongoid
119
119
  #
120
120
  # @param [ Hash ] options Options to pass to update.
121
121
  #
122
- # @option options [ true, false ] :validate Whether or not to validate.
122
+ # @option options [ true | false ] :validate Whether or not to validate.
123
123
  #
124
- # @return [ true, false ] True if succeeded, false if not.
124
+ # @return [ true | false ] True if succeeded, false if not.
125
125
  def update_document(options = {})
126
126
  prepare_update(options) do
127
127
  updates, conflicts = init_atomic_updates
@@ -36,7 +36,7 @@ module Mongoid
36
36
  #
37
37
  # @param [ Hash ] options The options hash.
38
38
  #
39
- # @return [ true, false ] If the operation succeeded.
39
+ # @return [ true | false ] If the operation succeeded.
40
40
  def prepare_upsert(options = {})
41
41
  return false if performing_validations?(options) && invalid?(:upsert)
42
42
  result = run_callbacks(:upsert) do
@@ -79,11 +79,11 @@ module Mongoid
79
79
  # document.set name: "Tool"
80
80
  # end
81
81
  #
82
- # @param [ true, false ] join_context Join the context (i.e. merge
82
+ # @param [ true | false ] join_context Join the context (i.e. merge
83
83
  # declared atomic operations) of the atomically block wrapping this one
84
84
  # for the same document, if one exists.
85
85
  #
86
- # @return [ true, false ] If the operation succeeded.
86
+ # @return [ true | false ] If the operation succeeded.
87
87
  def atomically(join_context: nil)
88
88
  join_context = Mongoid.join_contexts if join_context.nil?
89
89
  call_depth = @atomic_depth ||= 0
@@ -146,7 +146,7 @@ module Mongoid
146
146
  # @example Are we executing atomically?
147
147
  # document.executing_atomically?
148
148
  #
149
- # @return [ true, false ] If we are current executing atomically.
149
+ # @return [ true | false ] If we are current executing atomically.
150
150
  def executing_atomically?
151
151
  !@atomic_updates_to_execute_stack.nil?
152
152
  end
@@ -118,7 +118,7 @@ module Mongoid
118
118
  #
119
119
  # @param [ Object ] other The object to be compared with this one.
120
120
  #
121
- # @return [ true, false ] Whether the two persistence contexts are equal.
121
+ # @return [ true | false ] Whether the two persistence contexts are equal.
122
122
  def ==(other)
123
123
  return false unless other.is_a?(PersistenceContext)
124
124
  options == other.options
@@ -184,13 +184,12 @@ module Mongoid
184
184
  # PersistenceContext.set(model)
185
185
  #
186
186
  # @param [ Object ] object The class or model instance.
187
- # @param [ Hash, Mongoid::PersistenceContext ] options_or_context The persistence
187
+ # @param [ Hash | Mongoid::PersistenceContext ] options_or_context The persistence
188
188
  # options or a persistence context object.
189
189
  #
190
190
  # @return [ Mongoid::PersistenceContext ] The persistence context for the object.
191
191
  def set(object, options_or_context)
192
- key = "[mongoid][#{object.object_id}]:context"
193
- existing_context = Thread.current[key]
192
+ existing_context = get_context(object)
194
193
  existing_options = if existing_context
195
194
  existing_context.options
196
195
  else
@@ -201,7 +200,7 @@ module Mongoid
201
200
  end
202
201
  new_options = existing_options.merge(options_or_context)
203
202
  context = PersistenceContext.new(object, new_options)
204
- Thread.current[key] = context
203
+ store_context(object, context)
205
204
  end
206
205
 
207
206
  # Get the persistence context for a particular class or model instance.
@@ -213,7 +212,7 @@ module Mongoid
213
212
  #
214
213
  # @return [ Mongoid::PersistenceContext ] The persistence context for the object.
215
214
  def get(object)
216
- Thread.current["[mongoid][#{object.object_id}]:context"]
215
+ get_context(object)
217
216
  end
218
217
 
219
218
  # Clear the persistence context for a particular class or model instance.
@@ -221,7 +220,7 @@ module Mongoid
221
220
  # @example Clear the persistence context for a class or model instance.
222
221
  # PersistenceContext.clear(model)
223
222
  #
224
- # @param [ Class, Object ] object The class or model instance.
223
+ # @param [ Class | Object ] object The class or model instance.
225
224
  # @param [ Mongo::Cluster ] cluster The original cluster before this context was used.
226
225
  # @param [ Mongoid::PersistenceContext ] original_context The original persistence
227
226
  # context that was set before this context was used.
@@ -232,7 +231,44 @@ module Mongoid
232
231
  end
233
232
  end
234
233
  ensure
235
- Thread.current["[mongoid][#{object.object_id}]:context"] = original_context
234
+ store_context(object, original_context)
235
+ end
236
+
237
+ private
238
+
239
+ # Key to store persistence contexts in the thread local storage.
240
+ #
241
+ # @api private
242
+ PERSISTENCE_CONTEXT_KEY = :"[mongoid]:persistence_context"
243
+
244
+ # Get the persistence context for a given object from the thread local
245
+ # storage.
246
+ #
247
+ # @param [ Object ] object Object to get the persistance context for.
248
+ #
249
+ # @return [ Mongoid::PersistenceContext | nil ] The persistence context
250
+ # for the object if previously stored, otherwise nil.
251
+ #
252
+ # @api private
253
+ def get_context(object)
254
+ Thread.current[PERSISTENCE_CONTEXT_KEY] ||= {}
255
+ Thread.current[PERSISTENCE_CONTEXT_KEY][object.object_id]
256
+ end
257
+
258
+ # Store persistence context for a given object in the thread local
259
+ # storage.
260
+ #
261
+ # @param [ Object ] object Object to store the persistance context for.
262
+ # @param [ Mongoid::PersistenceContext ] context Context to store
263
+ #
264
+ # @api private
265
+ def store_context(object, context)
266
+ if context.nil?
267
+ Thread.current[PERSISTENCE_CONTEXT_KEY]&.delete(object.object_id)
268
+ else
269
+ Thread.current[PERSISTENCE_CONTEXT_KEY] ||= {}
270
+ Thread.current[PERSISTENCE_CONTEXT_KEY][object.object_id] = context
271
+ end
236
272
  end
237
273
  end
238
274
  end
@@ -22,7 +22,7 @@ module Mongoid
22
22
  # @example Set if the cache is enabled.
23
23
  # QueryCache.enabled = true
24
24
  #
25
- # @param [ true, false ] value The enabled value.
25
+ # @param [ true | false ] value The enabled value.
26
26
  def enabled=(value)
27
27
  Mongo::QueryCache.enabled = value
28
28
  end
@@ -32,7 +32,7 @@ module Mongoid
32
32
  # @example Is the query cache enabled?
33
33
  # QueryCache.enabled?
34
34
  #
35
- # @return [ true, false ] If the cache is enabled.
35
+ # @return [ true | false ] If the cache is enabled.
36
36
  def enabled?
37
37
  Mongo::QueryCache.enabled?
38
38
  end
@@ -23,7 +23,7 @@ module Mongoid
23
23
  # @example Apply the default scoping.
24
24
  # document.apply_default_scoping
25
25
  #
26
- # @return [ true, false ] If default scoping was applied.
26
+ # @return [ true | false ] If default scoping was applied.
27
27
  def apply_default_scoping
28
28
  if default_scoping
29
29
  default_scoping.call.selector.each do |field, value|
@@ -74,7 +74,7 @@ module Mongoid
74
74
  # default_scope ->{ where(active: true) }
75
75
  # end
76
76
  #
77
- # @param [ Proc, Criteria ] value The default scope.
77
+ # @param [ Proc | Criteria ] value The default scope.
78
78
  #
79
79
  # @raise [ Errors::InvalidScope ] If the scope is not a proc or criteria.
80
80
  #
@@ -90,7 +90,7 @@ module Mongoid
90
90
  # @example Can the default scope be applied?
91
91
  # Band.default_scopable?
92
92
  #
93
- # @return [ true, false ] If the default scope can be applied.
93
+ # @return [ true | false ] If the default scope can be applied.
94
94
  def default_scopable?
95
95
  default_scoping? && !Threaded.without_default_scope?(self)
96
96
  end
@@ -168,9 +168,11 @@ module Mongoid
168
168
  # Band.where(name: "Depeche Mode")
169
169
  # end
170
170
  #
171
- # @note This will force the default scope to be removed.
171
+ # @note This will force the default scope to be removed, but will not
172
+ # remove scopes declared with ``.with_scope``. This will be changed
173
+ # in Mongoid 9.
172
174
  #
173
- # @return [ Criteria, Object ] The unscoped criteria or result of the
175
+ # @return [ Criteria | Object ] The unscoped criteria or result of the
174
176
  # block.
175
177
  def unscoped
176
178
  if block_given?
@@ -240,7 +242,7 @@ module Mongoid
240
242
  # @example Warn or raise error if name exists.
241
243
  # Model.valid_scope_name?("test")
242
244
  #
243
- # @param [ String, Symbol ] name The name of the scope.
245
+ # @param [ String | Symbol ] name The name of the scope.
244
246
  #
245
247
  # @raise [ Errors::ScopeOverwrite ] If the name exists and configured to
246
248
  # raise the error.
@@ -249,12 +251,12 @@ module Mongoid
249
251
  if Mongoid.scope_overwrite_exception
250
252
  raise Errors::ScopeOverwrite.new(self.name, name)
251
253
  else
252
- if Mongoid.logger
253
- Mongoid.logger.warn(
254
- "Creating scope :#{name}. " +
255
- "Overwriting existing method #{self.name}.#{name}."
256
- )
257
- end
254
+ Mongoid.logger.warn(
255
+ "Creating scope :#{name} which conflicts with #{self.name}.#{name}. " +
256
+ "Calls to `Mongoid::Criteria##{name}` will delegate to " +
257
+ "`Mongoid::Criteria##{name}` for criteria with klass #{self.name} " +
258
+ "and will ignore the declared scope."
259
+ )
258
260
  end
259
261
  end
260
262
  end
@@ -289,15 +291,17 @@ module Mongoid
289
291
  # @return [ Method ] The defined method.
290
292
  def define_scope_method(name)
291
293
  singleton_class.class_eval do
292
- define_method(name) do |*args|
293
- scoping = _declared_scopes[name]
294
- scope = instance_exec(*args, &scoping[:scope])
295
- extension = scoping[:extension]
296
- to_merge = scope || queryable
297
- criteria = to_merge.empty_and_chainable? ? to_merge : with_default_scope.merge(to_merge)
298
- criteria.extend(extension)
299
- criteria
300
- end
294
+ ruby2_keywords(
295
+ define_method(name) do |*args|
296
+ scoping = _declared_scopes[name]
297
+ scope = instance_exec(*args, &scoping[:scope])
298
+ extension = scoping[:extension]
299
+ to_merge = scope || queryable
300
+ criteria = to_merge.empty_and_chainable? ? to_merge : with_default_scope.merge(to_merge)
301
+ criteria.extend(extension)
302
+ criteria
303
+ end
304
+ )
301
305
  end
302
306
  end
303
307
 
@@ -309,7 +313,7 @@ module Mongoid
309
313
  # @example Process the default scope.
310
314
  # Model.process_default_scope(value)
311
315
  #
312
- # @param [ Criteria, Proc ] value The default scope value.
316
+ # @param [ Criteria | Proc ] value The default scope value.
313
317
  def process_default_scope(value)
314
318
  if existing = default_scoping
315
319
  ->{ existing.call.merge(value.to_proc.call) }
@@ -33,10 +33,14 @@ module Mongoid
33
33
  #
34
34
  # @param [ Hash ] options The options to pass.
35
35
  #
36
- # @option options [ Symbol ] :include What associations to include.
37
- # @option options [ Symbol ] :only Limit the fields to only these.
38
- # @option options [ Symbol ] :except Dont include these fields.
39
- # @option options [ Symbol ] :methods What methods to include.
36
+ # @option options [ Symbol | String | Array<Symbol | String> ] :except
37
+ # Do not include these field(s).
38
+ # @option options [ Symbol | String | Array<Symbol | String> ] :include
39
+ # Which association(s) to include.
40
+ # @option options [ Symbol | String | Array<Symbol | String> ] :only
41
+ # Limit the field(s) to only these.
42
+ # @option options [ Symbol | String | Array<Symbol | String> ] :methods
43
+ # What methods to include.
40
44
  #
41
45
  # @return [ Hash ] The document, ready to be serialized.
42
46
  def serializable_hash(options = nil)
@@ -137,7 +141,7 @@ module Mongoid
137
141
  # @example Get the association names.
138
142
  # document.relation_names(:include => [ :addresses ])
139
143
  #
140
- # @param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
144
+ # @param [ Hash | Symbol | Array<Symbol> ] inclusions The inclusions.
141
145
  #
142
146
  # @return [ Array<Symbol> ] The names of the included associations.
143
147
  def relation_names(inclusions)
@@ -150,7 +154,7 @@ module Mongoid
150
154
  # @example Get the association options.
151
155
  # document.relation_names(:include => [ :addresses ])
152
156
  #
153
- # @param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
157
+ # @param [ Hash | Symbol | Array<Symbol> ] inclusions The inclusions.
154
158
  # @param [ Hash ] options The options.
155
159
  # @param [ Symbol ] name The name of the association.
156
160
  #
@@ -23,7 +23,7 @@ module Mongoid
23
23
  # @example Is the document new?
24
24
  # person.new_record?
25
25
  #
26
- # @return [ true, false ] True if new, false if not.
26
+ # @return [ true | false ] True if new, false if not.
27
27
  def new_record?
28
28
  @new_record ||= false
29
29
  end
@@ -32,7 +32,7 @@ module Mongoid
32
32
  # save, the object didn't exist in the database and new_record? would have
33
33
  # returned true.
34
34
  #
35
- # @return [ true, false ] True if was just created, false if not.
35
+ # @return [ true | false ] True if was just created, false if not.
36
36
  def previously_new_record?
37
37
  @previously_new_record ||= false
38
38
  end
@@ -43,7 +43,7 @@ module Mongoid
43
43
  # @example Is the document persisted?
44
44
  # person.persisted?
45
45
  #
46
- # @return [ true, false ] True if persisted, false if not.
46
+ # @return [ true | false ] True if persisted, false if not.
47
47
  def persisted?
48
48
  !new_record? && !destroyed?
49
49
  end
@@ -51,7 +51,7 @@ module Mongoid
51
51
  # Checks if the document was previously saved to the database
52
52
  # but now it has been deleted.
53
53
  #
54
- # @return [ true, false ] True if was persisted but now destroyed,
54
+ # @return [ true | false ] True if was persisted but now destroyed,
55
55
  # otherwise false.
56
56
  def previously_persisted?
57
57
  !new_record? && destroyed?
@@ -63,7 +63,7 @@ module Mongoid
63
63
  # @example Is the document flagged?
64
64
  # document.flagged_for_destroy?
65
65
  #
66
- # @return [ true, false ] If the document is flagged.
66
+ # @return [ true | false ] If the document is flagged.
67
67
  def flagged_for_destroy?
68
68
  @flagged_for_destroy ||= false
69
69
  end
@@ -77,7 +77,7 @@ module Mongoid
77
77
  # @example Is the document destroyed?
78
78
  # person.destroyed?
79
79
  #
80
- # @return [ true, false ] True if destroyed, false if not.
80
+ # @return [ true | false ] True if destroyed, false if not.
81
81
  def destroyed?
82
82
  @destroyed ||= false
83
83
  end
@@ -87,7 +87,7 @@ module Mongoid
87
87
  # @example Is this pushable?
88
88
  # person.pushable?
89
89
  #
90
- # @return [ true, false ] Is the document new and embedded?
90
+ # @return [ true | false ] Is the document new and embedded?
91
91
  def pushable?
92
92
  new_record? &&
93
93
  embedded_many? &&
@@ -100,7 +100,7 @@ module Mongoid
100
100
  # @example Is the document readonly?
101
101
  # document.readonly?
102
102
  #
103
- # @return [ true, false ] If the document is readonly.
103
+ # @return [ true | false ] If the document is readonly.
104
104
  def readonly?
105
105
  __selected_fields != nil
106
106
  end
@@ -110,7 +110,7 @@ module Mongoid
110
110
  # @example Is this settable?
111
111
  # person.settable?
112
112
  #
113
- # @return [ true, false ] Is this document a new embeds one?
113
+ # @return [ true | false ] Is this document a new embeds one?
114
114
  def settable?
115
115
  new_record? && embedded_one? && _parent.persisted?
116
116
  end
@@ -120,7 +120,7 @@ module Mongoid
120
120
  # @example Is the document updateable?
121
121
  # person.updateable?
122
122
  #
123
- # @return [ true, false ] If the document is changed and persisted.
123
+ # @return [ true | false ] If the document is changed and persisted.
124
124
  def updateable?
125
125
  persisted? && changed?
126
126
  end
@@ -36,7 +36,6 @@ module Mongoid
36
36
  # Mongoid::Tasks::Database.undefined_indexes
37
37
  #
38
38
  # @return [ Array<Hash> ] The list of undefined indexes by model.
39
- #
40
39
  def undefined_indexes(models = ::Mongoid.models)
41
40
  undefined_by_model = {}
42
41
 
@@ -90,7 +89,6 @@ module Mongoid
90
89
  # Mongoid::Tasks::Database.remove_indexes
91
90
  #
92
91
  # @return [ Array<Class> ] The un-indexed models.
93
- #
94
92
  def remove_indexes(models = ::Mongoid.models)
95
93
  models.each do |model|
96
94
  next if model.embedded?
@@ -37,7 +37,7 @@ module Mongoid
37
37
  # @example Is the current thread in assigning mode?
38
38
  # proxy._assigning?
39
39
  #
40
- # @return [ true, false ] If the thread is assigning.
40
+ # @return [ true | false ] If the thread is assigning.
41
41
  def _assigning?
42
42
  Threaded.executing?(ASSIGN)
43
43
  end
@@ -62,7 +62,7 @@ module Mongoid
62
62
  # @example Is the current thread in binding mode?
63
63
  # proxy.binding?
64
64
  #
65
- # @return [ true, false ] If the thread is binding.
65
+ # @return [ true | false ] If the thread is binding.
66
66
  def _binding?
67
67
  Threaded.executing?(BIND)
68
68
  end
@@ -87,7 +87,7 @@ module Mongoid
87
87
  # @example Is the current thread in building mode?
88
88
  # proxy._building?
89
89
  #
90
- # @return [ true, false ] If the thread is building.
90
+ # @return [ true | false ] If the thread is building.
91
91
  def _building?
92
92
  Threaded.executing?(BUILD)
93
93
  end
@@ -97,7 +97,7 @@ module Mongoid
97
97
  # @example Is the current thread in creating mode?
98
98
  # proxy.creating?
99
99
  #
100
- # @return [ true, false ] If the thread is creating.
100
+ # @return [ true | false ] If the thread is creating.
101
101
  def _creating?
102
102
  Threaded.executing?(CREATE)
103
103
  end
@@ -122,7 +122,7 @@ module Mongoid
122
122
  # @example Is the current thread in loading mode?
123
123
  # proxy._loading?
124
124
  #
125
- # @return [ true, false ] If the thread is loading.
125
+ # @return [ true | false ] If the thread is loading.
126
126
  def _loading?
127
127
  Threaded.executing?(LOAD)
128
128
  end
@@ -45,7 +45,7 @@ module Mongoid
45
45
  # @example Get the global database override.
46
46
  # Threaded.database_override
47
47
  #
48
- # @return [ String, Symbol ] The override.
48
+ # @return [ String | Symbol ] The override.
49
49
  def database_override
50
50
  Thread.current[DATABASE_OVERRIDE_KEY]
51
51
  end
@@ -55,9 +55,9 @@ module Mongoid
55
55
  # @example Set the global database override.
56
56
  # Threaded.database_override = :testing
57
57
  #
58
- # @param [ String, Symbol ] name The global override name.
58
+ # @param [ String | Symbol ] name The global override name.
59
59
  #
60
- # @return [ String, Symbol ] The override.
60
+ # @return [ String | Symbol ] The override.
61
61
  def database_override=(name)
62
62
  Thread.current[DATABASE_OVERRIDE_KEY] = name
63
63
  end
@@ -167,7 +167,7 @@ module Mongoid
167
167
  # @example Get the global client override.
168
168
  # Threaded.client_override
169
169
  #
170
- # @return [ String, Symbol ] The override.
170
+ # @return [ String | Symbol ] The override.
171
171
  def client_override
172
172
  Thread.current[CLIENT_OVERRIDE_KEY]
173
173
  end
@@ -177,9 +177,9 @@ module Mongoid
177
177
  # @example Set the global client override.
178
178
  # Threaded.client_override = :testing
179
179
  #
180
- # @param [ String, Symbol ] name The global override name.
180
+ # @param [ String | Symbol ] name The global override name.
181
181
  #
182
- # @return [ String, Symbol ] The override.
182
+ # @return [ String | Symbol ] The override.
183
183
  def client_override=(name)
184
184
  Thread.current[CLIENT_OVERRIDE_KEY] = name
185
185
  end
@@ -255,7 +255,7 @@ module Mongoid
255
255
  #
256
256
  # @param [ Document ] document The document to check.
257
257
  #
258
- # @return [ true, false ] If the document is autosaved.
258
+ # @return [ true | false ] If the document is autosaved.
259
259
  def autosaved?(document)
260
260
  autosaves_for(document.class).include?(document._id)
261
261
  end
@@ -267,7 +267,7 @@ module Mongoid
267
267
  #
268
268
  # @param [ Document ] document The document to check.
269
269
  #
270
- # @return [ true, false ] If the document is validated.
270
+ # @return [ true | false ] If the document is validated.
271
271
  def validated?(document)
272
272
  validations_for(document.class).include?(document._id)
273
273
  end
@@ -322,7 +322,7 @@ module Mongoid
322
322
  #
323
323
  # @param [ Mongo::Session ] session The session to save.
324
324
  def set_session(session)
325
- Thread.current[:session] = session
325
+ Thread.current["[mongoid]:session"] = session
326
326
  end
327
327
 
328
328
  # Get the cached session for this thread.
@@ -330,9 +330,9 @@ module Mongoid
330
330
  # @example Get the session for this thread.
331
331
  # Threaded.get_session
332
332
  #
333
- # @return [ Mongo::Session, nil ] The session cached on this thread or nil.
333
+ # @return [ Mongo::Session | nil ] The session cached on this thread or nil.
334
334
  def get_session
335
- Thread.current[:session]
335
+ Thread.current["[mongoid]:session"]
336
336
  end
337
337
 
338
338
  # Clear the cached session for this thread.
@@ -344,7 +344,7 @@ module Mongoid
344
344
  def clear_session
345
345
  session = get_session
346
346
  session.end_session if session
347
- Thread.current[:session] = nil
347
+ Thread.current["[mongoid]:session"] = nil
348
348
  end
349
349
  end
350
350
  end
@@ -35,7 +35,7 @@ module Mongoid
35
35
  # @example Can the timestamp be set?
36
36
  # document.able_to_set_updated_at?
37
37
  #
38
- # @return [ true, false ] If the timestamp can be set.
38
+ # @return [ true | false ] If the timestamp can be set.
39
39
  def able_to_set_updated_at?
40
40
  !frozen? && !timeless? && (new_record? || changed?)
41
41
  end
@@ -203,7 +203,7 @@ module Mongoid
203
203
  # @example Check if the document is a subclass
204
204
  # Square.new.hereditary?
205
205
  #
206
- # @return [ true, false ] True if hereditary, false if not.
206
+ # @return [ true | false ] True if hereditary, false if not.
207
207
  def hereditary?
208
208
  self.class.hereditary?
209
209
  end
@@ -283,7 +283,7 @@ module Mongoid
283
283
  # @example Is the document the root?
284
284
  # document._root?
285
285
  #
286
- # @return [ true, false ] If the document is the root.
286
+ # @return [ true | false ] If the document is the root.
287
287
  def _root?
288
288
  _parent ? false : true
289
289
  end
@@ -295,7 +295,7 @@ module Mongoid
295
295
  # @example Check if the document is a subclass.
296
296
  # Square.hereditary?
297
297
  #
298
- # @return [ true, false ] True if hereditary, false if not.
298
+ # @return [ true | false ] True if hereditary, false if not.
299
299
  def hereditary?
300
300
  !!(Mongoid::Document > superclass)
301
301
  end
@@ -12,7 +12,7 @@ module Mongoid
12
12
  # validator.validate_each(model, :name, "value")
13
13
  #
14
14
  # @param [ Document ] document The document.
15
- # @param [ Symbol, String ] attribute The attribute to validate.
15
+ # @param [ Symbol | String ] attribute The attribute to validate.
16
16
  # @param [ Object ] value The attribute value.
17
17
  def validate_each(document, attribute, value)
18
18
  field = document.fields[document.database_field_name(attribute)]
@@ -19,7 +19,6 @@ module Mongoid
19
19
  # end
20
20
  #
21
21
  # @param [ Array ] args The arguments to pass to the validator.
22
- #
23
22
  def validates_associated(*args)
24
23
  validates_with(AssociatedValidator, _merge_attributes(args))
25
24
  end
@@ -37,7 +36,6 @@ module Mongoid
37
36
  # end
38
37
  #
39
38
  # @param [ Array ] args The arguments to pass to the validator.
40
- #
41
39
  def validates_uniqueness_of(*args)
42
40
  validates_with(UniquenessValidator, _merge_attributes(args))
43
41
  end
@@ -56,7 +56,7 @@ module Mongoid
56
56
  # @param [ Symbol ] attr The attribute.
57
57
  # @param [ Object ] value The value.
58
58
  #
59
- # @return [ true, false ] If the doc is missing.
59
+ # @return [ true | false ] If the doc is missing.
60
60
  def relation_or_fk_missing?(doc, attr, value)
61
61
  return true if value.blank? && doc.send(attr).blank?
62
62
  association = doc.relations[attr.to_s]
@@ -72,7 +72,7 @@ module Mongoid
72
72
  #
73
73
  # @param [ Object ] value The value.
74
74
  #
75
- # @return [ true, false ] If the value is not present.
75
+ # @return [ true | false ] If the value is not present.
76
76
  def not_present?(value)
77
77
  value.blank? && value != false
78
78
  end