mongoid 8.0.1 → 8.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.
Files changed (144) 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/changeable.rb +5 -5
  47. data/lib/mongoid/clients/options.rb +1 -1
  48. data/lib/mongoid/clients/validators/storage.rb +3 -3
  49. data/lib/mongoid/config/validators/client.rb +6 -6
  50. data/lib/mongoid/config.rb +7 -7
  51. data/lib/mongoid/contextual/aggregable/memory.rb +1 -1
  52. data/lib/mongoid/contextual/aggregable/mongo.rb +4 -4
  53. data/lib/mongoid/contextual/aggregable/none.rb +1 -1
  54. data/lib/mongoid/contextual/atomic.rb +1 -1
  55. data/lib/mongoid/contextual/geo_near.rb +7 -7
  56. data/lib/mongoid/contextual/memory.rb +5 -5
  57. data/lib/mongoid/contextual/mongo.rb +14 -14
  58. data/lib/mongoid/contextual/none.rb +2 -2
  59. data/lib/mongoid/contextual/queryable.rb +1 -1
  60. data/lib/mongoid/contextual.rb +2 -2
  61. data/lib/mongoid/criteria/findable.rb +7 -4
  62. data/lib/mongoid/criteria/includable.rb +1 -1
  63. data/lib/mongoid/criteria/permission.rb +1 -1
  64. data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
  65. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  66. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +2 -2
  67. data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
  68. data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -3
  69. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +1 -1
  70. data/lib/mongoid/criteria/queryable/key.rb +3 -3
  71. data/lib/mongoid/criteria/queryable/optional.rb +2 -2
  72. data/lib/mongoid/criteria/queryable/options.rb +1 -1
  73. data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
  74. data/lib/mongoid/criteria/queryable/selectable.rb +3 -3
  75. data/lib/mongoid/criteria/queryable/selector.rb +3 -3
  76. data/lib/mongoid/criteria/queryable/smash.rb +1 -1
  77. data/lib/mongoid/criteria/queryable.rb +1 -1
  78. data/lib/mongoid/criteria/scopable.rb +2 -2
  79. data/lib/mongoid/criteria.rb +14 -9
  80. data/lib/mongoid/deprecable.rb +1 -1
  81. data/lib/mongoid/document.rb +2 -2
  82. data/lib/mongoid/equality.rb +12 -12
  83. data/lib/mongoid/errors/document_not_found.rb +5 -5
  84. data/lib/mongoid/errors/invalid_config_option.rb +1 -1
  85. data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
  86. data/lib/mongoid/errors/invalid_field.rb +1 -1
  87. data/lib/mongoid/errors/invalid_relation.rb +1 -1
  88. data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
  89. data/lib/mongoid/errors/invalid_session_use.rb +1 -1
  90. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  91. data/lib/mongoid/errors/mongoid_error.rb +3 -3
  92. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
  93. data/lib/mongoid/errors/no_client_database.rb +1 -1
  94. data/lib/mongoid/errors/no_client_hosts.rb +1 -1
  95. data/lib/mongoid/errors/readonly_attribute.rb +1 -1
  96. data/lib/mongoid/errors/unknown_attribute.rb +1 -1
  97. data/lib/mongoid/extensions/array.rb +1 -1
  98. data/lib/mongoid/extensions/false_class.rb +1 -1
  99. data/lib/mongoid/extensions/hash.rb +1 -1
  100. data/lib/mongoid/extensions/module.rb +1 -1
  101. data/lib/mongoid/extensions/object.rb +6 -6
  102. data/lib/mongoid/extensions/string.rb +9 -9
  103. data/lib/mongoid/extensions/symbol.rb +1 -1
  104. data/lib/mongoid/extensions/true_class.rb +1 -1
  105. data/lib/mongoid/fields/foreign_key.rb +4 -4
  106. data/lib/mongoid/fields/localized.rb +2 -2
  107. data/lib/mongoid/fields/standard.rb +7 -7
  108. data/lib/mongoid/fields.rb +9 -9
  109. data/lib/mongoid/findable.rb +7 -6
  110. data/lib/mongoid/indexable/specification.rb +1 -1
  111. data/lib/mongoid/indexable/validators/options.rb +2 -1
  112. data/lib/mongoid/interceptable.rb +4 -4
  113. data/lib/mongoid/matchable.rb +1 -1
  114. data/lib/mongoid/matcher.rb +12 -7
  115. data/lib/mongoid/persistable/creatable.rb +4 -4
  116. data/lib/mongoid/persistable/deletable.rb +1 -1
  117. data/lib/mongoid/persistable/destroyable.rb +1 -1
  118. data/lib/mongoid/persistable/savable.rb +2 -2
  119. data/lib/mongoid/persistable/unsettable.rb +1 -1
  120. data/lib/mongoid/persistable/updatable.rb +7 -7
  121. data/lib/mongoid/persistable/upsertable.rb +1 -1
  122. data/lib/mongoid/persistable.rb +3 -3
  123. data/lib/mongoid/persistence_context.rb +3 -3
  124. data/lib/mongoid/query_cache.rb +2 -2
  125. data/lib/mongoid/scopable.rb +17 -15
  126. data/lib/mongoid/serializable.rb +10 -6
  127. data/lib/mongoid/stateful.rb +10 -10
  128. data/lib/mongoid/tasks/database.rb +0 -2
  129. data/lib/mongoid/threaded/lifecycle.rb +5 -5
  130. data/lib/mongoid/threaded.rb +9 -9
  131. data/lib/mongoid/timestamps/updated.rb +1 -1
  132. data/lib/mongoid/traversable.rb +3 -3
  133. data/lib/mongoid/validatable/localizable.rb +1 -1
  134. data/lib/mongoid/validatable/macros.rb +0 -2
  135. data/lib/mongoid/validatable/presence.rb +2 -2
  136. data/lib/mongoid/validatable/uniqueness.rb +7 -7
  137. data/lib/mongoid/validatable.rb +6 -6
  138. data/lib/mongoid/version.rb +1 -1
  139. data/spec/mongoid/equality_spec.rb +12 -12
  140. data/spec/mongoid/indexable_spec.rb +23 -1
  141. data/spec/mongoid/scopable_spec.rb +34 -16
  142. data.tar.gz.sig +0 -0
  143. metadata +2 -2
  144. metadata.gz.sig +0 -0
@@ -12,7 +12,7 @@ module Mongoid
12
12
  # self
13
13
  # end
14
14
  #
15
- # @param [ String, Symbol ] name The name of the method.
15
+ # @param [ String | Symbol ] name The name of the method.
16
16
  # @param [ Proc ] block The method body.
17
17
  #
18
18
  # @return [ Method ] The new method.
@@ -90,10 +90,10 @@ module Mongoid
90
90
  # @example Do or do not.
91
91
  # object.do_or_do_not(:use, "The Force")
92
92
  #
93
- # @param [ String, Symbol ] name The method name.
93
+ # @param [ String | Symbol ] name The method name.
94
94
  # @param [ Array ] args The arguments.
95
95
  #
96
- # @return [ Object, nil ] The result of the method call or nil if the
96
+ # @return [ Object | nil ] The result of the method call or nil if the
97
97
  # method does not exist.
98
98
  def do_or_do_not(name, *args)
99
99
  send(name, *args) if name && respond_to?(name)
@@ -106,7 +106,7 @@ module Mongoid
106
106
  #
107
107
  # @param [ String ] name The name of the variable.
108
108
  #
109
- # @return [ Object, false ] The value or false.
109
+ # @return [ Object | false ] The value or false.
110
110
  def ivar(name)
111
111
  var_name = "@_#{name}"
112
112
  if instance_variable_defined?(var_name)
@@ -154,7 +154,7 @@ module Mongoid
154
154
  #
155
155
  # @param [ String ] name The name of the variable.
156
156
  #
157
- # @return [ true, false ] If the variable was defined.
157
+ # @return [ true | false ] If the variable was defined.
158
158
  def remove_ivar(name)
159
159
  if instance_variable_defined?("@_#{name}")
160
160
  return remove_instance_variable("@_#{name}")
@@ -189,10 +189,10 @@ module Mongoid
189
189
  # @example You must perform this execution.
190
190
  # object.you_must(:use, "The Force")
191
191
  #
192
- # @param [ String, Symbol ] name The method name.
192
+ # @param [ String | Symbol ] name The method name.
193
193
  # @param [ Array ] args The arguments.
194
194
  #
195
- # @return [ Object, nil ] The result of the method call or nil if the
195
+ # @return [ Object | nil ] The result of the method call or nil if the
196
196
  # method does not exist. Nil if the object is frozen.
197
197
  def you_must(name, *args)
198
198
  frozen? ? nil : do_or_do_not(name, *args)
@@ -12,7 +12,7 @@ module Mongoid
12
12
  # @example Evolve the string.
13
13
  # "test".__evolve_object_id__
14
14
  #
15
- # @return [ String, BSON::ObjectId ] The evolved string.
15
+ # @return [ String | BSON::ObjectId ] The evolved string.
16
16
  def __evolve_object_id__
17
17
  convert_to_object_id
18
18
  end
@@ -22,7 +22,7 @@ module Mongoid
22
22
  # @example Evolve the string.
23
23
  # "test".__mongoize_object_id__
24
24
  #
25
- # @return [ String, BSON::ObjectId, nil ] The mongoized string.
25
+ # @return [ String | BSON::ObjectId | nil ] The mongoized string.
26
26
  def __mongoize_object_id__
27
27
  convert_to_object_id unless blank?
28
28
  end
@@ -65,7 +65,7 @@ module Mongoid
65
65
  # @example Is the string an id value?
66
66
  # "_id".mongoid_id?
67
67
  #
68
- # @return [ true, false ] If the string is id or _id.
68
+ # @return [ true | false ] If the string is id or _id.
69
69
  def mongoid_id?
70
70
  self =~ /\A(|_)id\z/
71
71
  end
@@ -76,7 +76,7 @@ module Mongoid
76
76
  # @example Is the string a number.
77
77
  # "1234.23".numeric?
78
78
  #
79
- # @return [ true, false ] If the string is a number.
79
+ # @return [ true | false ] If the string is a number.
80
80
  def numeric?
81
81
  !!Float(self)
82
82
  rescue ArgumentError
@@ -98,7 +98,7 @@ module Mongoid
98
98
  # @example Is the string a setter method?
99
99
  # "model=".writer?
100
100
  #
101
- # @return [ true, false ] If the string contains "=".
101
+ # @return [ true | false ] If the string contains "=".
102
102
  def writer?
103
103
  include?("=")
104
104
  end
@@ -108,7 +108,7 @@ module Mongoid
108
108
  # @example Is the string a valid Ruby identifier for use as a method name
109
109
  # "model=".valid_method_name?
110
110
  #
111
- # @return [ true, false ] If the string contains a valid Ruby identifier.
111
+ # @return [ true | false ] If the string contains a valid Ruby identifier.
112
112
  def valid_method_name?
113
113
  /[@$"-]/ !~ self
114
114
  end
@@ -118,7 +118,7 @@ module Mongoid
118
118
  # @example Is the string a setter method?
119
119
  # "price_before_type_cast".before_type_cast?
120
120
  #
121
- # @return [ true, false ] If the string ends with "_before_type_cast"
121
+ # @return [ true | false ] If the string ends with "_before_type_cast"
122
122
  def before_type_cast?
123
123
  ends_with?("_before_type_cast")
124
124
  end
@@ -128,7 +128,7 @@ module Mongoid
128
128
  # @example Is the object unconvertable?
129
129
  # object.unconvertable_to_bson?
130
130
  #
131
- # @return [ true, false ] If the object is unconvertable.
131
+ # @return [ true | false ] If the object is unconvertable.
132
132
  def unconvertable_to_bson?
133
133
  @unconvertable_to_bson ||= false
134
134
  end
@@ -142,7 +142,7 @@ module Mongoid
142
142
  # @example Convert to the object id.
143
143
  # string.convert_to_object_id
144
144
  #
145
- # @return [ String, BSON::ObjectId ] The string or the id.
145
+ # @return [ String | BSON::ObjectId ] The string or the id.
146
146
  def convert_to_object_id
147
147
  BSON::ObjectId.legal?(self) ? BSON::ObjectId.from_string(self) : self
148
148
  end
@@ -9,7 +9,7 @@ module Mongoid
9
9
  # @example Is the string an id value?
10
10
  # :_id.mongoid_id?
11
11
  #
12
- # @return [ true, false ] If the symbol is :id or :_id.
12
+ # @return [ true | false ] If the symbol is :id or :_id.
13
13
  def mongoid_id?
14
14
  to_s.mongoid_id?
15
15
  end
@@ -21,7 +21,7 @@ module Mongoid
21
21
  #
22
22
  # @param [ Class ] other The class to check.
23
23
  #
24
- # @return [ true, false ] If the other is a boolean.
24
+ # @return [ true | false ] If the other is a boolean.
25
25
  def is_a?(other)
26
26
  if other == Mongoid::Boolean || other.class == Mongoid::Boolean
27
27
  return true
@@ -43,7 +43,7 @@ module Mongoid
43
43
  # @example Is the field a foreign key?
44
44
  # field.foreign_key?
45
45
  #
46
- # @return [ true, false ] If the field is a foreign key.
46
+ # @return [ true | false ] If the field is a foreign key.
47
47
  def foreign_key?
48
48
  true
49
49
  end
@@ -75,7 +75,7 @@ module Mongoid
75
75
  # @example Is the field lazy?
76
76
  # field.lazy?
77
77
  #
78
- # @return [ true, false ] If the field is lazy.
78
+ # @return [ true | false ] If the field is lazy.
79
79
  def lazy?
80
80
  type.resizable?
81
81
  end
@@ -101,7 +101,7 @@ module Mongoid
101
101
  # @example Is the field a BSON::ObjectId?
102
102
  # field.object_id_field?
103
103
  #
104
- # @return [ true, false ] If the field is a BSON::ObjectId.
104
+ # @return [ true | false ] If the field is a BSON::ObjectId.
105
105
  def object_id_field?
106
106
  @object_id_field ||=
107
107
  association.polymorphic? ? true : association.klass.using_object_ids?
@@ -112,7 +112,7 @@ module Mongoid
112
112
  # @example Is the field resizable?
113
113
  # field.resizable?
114
114
  #
115
- # @return [ true, false ] If the field is resizable.
115
+ # @return [ true | false ] If the field is resizable.
116
116
  def resizable?
117
117
  type.resizable?
118
118
  end
@@ -24,7 +24,7 @@ module Mongoid
24
24
  # @example Is the field localized?
25
25
  # field.localized?
26
26
  #
27
- # @return [ true, false ] If the field is localized.
27
+ # @return [ true | false ] If the field is localized.
28
28
  def localized?
29
29
  true
30
30
  end
@@ -50,7 +50,7 @@ module Mongoid
50
50
  # @example Should fallbacks be used.
51
51
  # field.fallbacks?
52
52
  #
53
- # @return [ true, false ] If fallbacks should be used.
53
+ # @return [ true | false ] If fallbacks should be used.
54
54
  def fallbacks?
55
55
  return true if options[:fallbacks].nil?
56
56
  !!options[:fallbacks]
@@ -48,7 +48,7 @@ module Mongoid
48
48
  # @example Is the field a foreign key?
49
49
  # field.foreign_key?
50
50
  #
51
- # @return [ true, false ] If the field is a foreign key.
51
+ # @return [ true | false ] If the field is a foreign key.
52
52
  def foreign_key?
53
53
  false
54
54
  end
@@ -82,7 +82,7 @@ module Mongoid
82
82
  # @example Is the field lazy?
83
83
  # field.lazy?
84
84
  #
85
- # @return [ true, false ] If the field is lazy.
85
+ # @return [ true | false ] If the field is lazy.
86
86
  def lazy?
87
87
  false
88
88
  end
@@ -92,7 +92,7 @@ module Mongoid
92
92
  # @example Is the field localized?
93
93
  # field.localized?
94
94
  #
95
- # @return [ true, false ] If the field is localized.
95
+ # @return [ true | false ] If the field is localized.
96
96
  def localized?
97
97
  false
98
98
  end
@@ -112,7 +112,7 @@ module Mongoid
112
112
  # @example Is the field a BSON::ObjectId?
113
113
  # field.object_id_field?
114
114
  #
115
- # @return [ true, false ] If the field is a BSON::ObjectId.
115
+ # @return [ true | false ] If the field is a BSON::ObjectId.
116
116
  def object_id_field?
117
117
  @object_id_field ||= (type == BSON::ObjectId)
118
118
  end
@@ -122,7 +122,7 @@ module Mongoid
122
122
  # @example Does the field pre-process the default?
123
123
  # field.pre_processed?
124
124
  #
125
- # @return [ true, false ] If the field's default is pre-processed.
125
+ # @return [ true | false ] If the field's default is pre-processed.
126
126
  def pre_processed?
127
127
  @pre_processed ||=
128
128
  (options[:pre_processed] || (default_val && !default_val.is_a?(::Proc)))
@@ -161,7 +161,7 @@ module Mongoid
161
161
  #
162
162
  # @note Ruby's instance_exec was just too slow.
163
163
  #
164
- # @param [ Class, Module ] object The class or module the field is
164
+ # @param [ Class | Module ] object The class or module the field is
165
165
  # defined on.
166
166
  def define_default_method(object)
167
167
  object.__send__(:define_method, default_name, default_val)
@@ -177,7 +177,7 @@ module Mongoid
177
177
  #
178
178
  # @param [ Hash ] fields The field limitations.
179
179
  #
180
- # @return [ true, false ] If the field was included.
180
+ # @return [ true | false ] If the field was included.
181
181
  def included?(fields)
182
182
  (fields.values.first == 1 && fields[name.to_s] == 1) ||
183
183
  (fields.values.first == 0 && !fields.has_key?(name.to_s))
@@ -147,7 +147,7 @@ module Mongoid
147
147
  # @example Apply all the non-proc defaults.
148
148
  # model.apply_pre_processed_defaults
149
149
  #
150
- # @return [ Array<String ] The names of the non-proc defaults.
150
+ # @return [ Array<String> ] The names of the non-proc defaults.
151
151
  def apply_pre_processed_defaults
152
152
  pre_processed_defaults.each do |name|
153
153
  apply_default(name)
@@ -159,7 +159,7 @@ module Mongoid
159
159
  # @example Apply all the proc defaults.
160
160
  # model.apply_post_processed_defaults
161
161
  #
162
- # @return [ Array<String ] The names of the proc defaults.
162
+ # @return [ Array<String> ] The names of the proc defaults.
163
163
  def apply_post_processed_defaults
164
164
  pending_callbacks.delete(:apply_post_processed_defaults)
165
165
  post_processed_defaults.each do |name|
@@ -214,7 +214,7 @@ module Mongoid
214
214
  # @example Get the database field name.
215
215
  # model.database_field_name(:authorization)
216
216
  #
217
- # @param [ String, Symbol ] name The name to get.
217
+ # @param [ String | Symbol ] name The name to get.
218
218
  #
219
219
  # @return [ String ] The name of the field as it's stored in the db.
220
220
  def database_field_name(name)
@@ -229,7 +229,7 @@ module Mongoid
229
229
  # @param [ Field ] field The field.
230
230
  # @param [ Object ] value The current value.
231
231
  #
232
- # @return [ true, false ] If we set the field lazily.
232
+ # @return [ true | false ] If we set the field lazily.
233
233
  def lazy_settable?(field, value)
234
234
  !frozen? && value.nil? && field.lazy?
235
235
  end
@@ -241,7 +241,7 @@ module Mongoid
241
241
  # @example Is the document using object ids?
242
242
  # model.using_object_ids?
243
243
  #
244
- # @return [ true, false ] Using object ids.
244
+ # @return [ true | false ] Using object ids.
245
245
  def using_object_ids?
246
246
  self.class.using_object_ids?
247
247
  end
@@ -252,7 +252,7 @@ module Mongoid
252
252
  #
253
253
  # @param [ String ] name The field name.
254
254
  #
255
- # @return [ true, false ] If this field is dotted or dollared.
255
+ # @return [ true | false ] If this field is dotted or dollared.
256
256
  def dot_dollar_field?(name)
257
257
  n = aliased_fields[name] || name
258
258
  fields.key?(n) && (n.include?('.') || n.start_with?('$'))
@@ -396,7 +396,7 @@ module Mongoid
396
396
  # If the belongs_to association is the last part of the name, we will
397
397
  # pass back the _id field.
398
398
  #
399
- # @param [ String, Symbol ] name The name to get.
399
+ # @param [ String | Symbol ] name The name to get.
400
400
  # @param [ Hash ] relations The associations.
401
401
  # @param [ Hash ] alaiased_fields The aliased fields.
402
402
  # @param [ Hash ] alaiased_associations The aliased associations.
@@ -455,7 +455,7 @@ module Mongoid
455
455
  # Get the name of the provided field as it is stored in the database.
456
456
  # Used in determining if the field is aliased or not.
457
457
  #
458
- # @param [ String, Symbol ] name The name to get.
458
+ # @param [ String | Symbol ] name The name to get.
459
459
  #
460
460
  # @return [ String ] The name of the field as it's stored in the db.
461
461
  def database_field_name(name)
@@ -507,7 +507,7 @@ module Mongoid
507
507
  # @example Does this class use object ids?
508
508
  # person.using_object_ids?
509
509
  #
510
- # @return [ true, false ] If the class uses BSON::ObjectIds for the id.
510
+ # @return [ true | false ] If the class uses BSON::ObjectIds for the id.
511
511
  def using_object_ids?
512
512
  fields["_id"].object_id_field?
513
513
  end
@@ -76,7 +76,7 @@ module Mongoid
76
76
  # @example Are there no saved documents for this model?
77
77
  # Person.empty?
78
78
  #
79
- # @return [ true, false ] If the collection is empty.
79
+ # @return [ true | false ] If the collection is empty.
80
80
  def empty?
81
81
  count == 0
82
82
  end
@@ -87,7 +87,7 @@ module Mongoid
87
87
  # @example Do any documents exist for the conditions?
88
88
  # Person.exists?
89
89
  #
90
- # @return [ true, false ] If any documents exist for the conditions.
90
+ # @return [ true | false ] If any documents exist for the conditions.
91
91
  def exists?
92
92
  with_default_scope.exists?
93
93
  end
@@ -132,8 +132,10 @@ module Mongoid
132
132
  # The +find+ method takes into account the default scope defined on the
133
133
  # model class, if any.
134
134
  #
135
- # @param [ Object | Array<Object> ] args The _id values to find or an
136
- # array thereof.
135
+ # @note Each argument can be an individual id, an array of ids or
136
+ # a nested array. Each array will be flattened.
137
+ #
138
+ # @param [ Object | Array<Object> ] *args The _id value(s) to find.
137
139
  #
138
140
  # @return [ Document | Array<Document> | nil ] A document or matching documents.
139
141
  #
@@ -161,7 +163,7 @@ module Mongoid
161
163
  # @raise [ Errors::DocumentNotFound ] If no document found
162
164
  # and Mongoid.raise_not_found_error is true.
163
165
  #
164
- # @return [ Document, nil ] A matching document.
166
+ # @return [ Document | nil ] A matching document.
165
167
  def find_by(attrs = {})
166
168
  result = where(attrs).find_first
167
169
  if result.nil? && Mongoid.raise_not_found_error
@@ -182,7 +184,6 @@ module Mongoid
182
184
  # @raise [ Errors::DocumentNotFound ] If no document found.
183
185
  #
184
186
  # @return [ Document ] A matching document.
185
- #
186
187
  def find_by!(attrs = {})
187
188
  result = where(attrs).find_first
188
189
  raise(Errors::DocumentNotFound.new(self, attrs)) unless result
@@ -27,7 +27,7 @@ module Mongoid
27
27
  #
28
28
  # @param [ Specification ] other The spec to compare against.
29
29
  #
30
- # @return [ true, false ] If the specs are equal.
30
+ # @return [ true | false ] If the specs are equal.
31
31
  def ==(other)
32
32
  fields == other.fields && key == other.key
33
33
  end
@@ -28,7 +28,8 @@ module Mongoid
28
28
  :text_version,
29
29
  :version,
30
30
  :partial_filter_expression,
31
- :collation
31
+ :collation,
32
+ :wildcard_projection,
32
33
  ]
33
34
 
34
35
  VALID_TYPES = [
@@ -53,7 +53,7 @@ module Mongoid
53
53
  #
54
54
  # @param [ Symbol ] kind The type of callback.
55
55
  #
56
- # @return [ true, false ] If the callback can be executed.
56
+ # @return [ true | false ] If the callback can be executed.
57
57
  def callback_executable?(kind)
58
58
  respond_to?("_#{kind}_callbacks")
59
59
  end
@@ -66,7 +66,7 @@ module Mongoid
66
66
  #
67
67
  # @param [ Symbol ] kind The callback kind.
68
68
  #
69
- # @return [ true, false ] If the document is in a callback state.
69
+ # @return [ true | false ] If the document is in a callback state.
70
70
  def in_callback_state?(kind)
71
71
  [ :create, :destroy ].include?(kind) || new_record? || flagged_for_destroy? || changed?
72
72
  end
@@ -195,7 +195,7 @@ module Mongoid
195
195
  # @example Was a before callback halted?
196
196
  # document.before_callback_halted?
197
197
  #
198
- # @return [ true, false ] If a before callback was halted.
198
+ # @return [ true | false ] If a before callback was halted.
199
199
  def before_callback_halted?
200
200
  !!@before_callback_halted
201
201
  end
@@ -235,7 +235,7 @@ module Mongoid
235
235
  # @param [ Symbol ] kind The type of callback.
236
236
  # @param [ Document ] child The child document.
237
237
  #
238
- # @return [ true, false ] If the child should fire the callback.
238
+ # @return [ true | false ] If the child should fire the callback.
239
239
  def cascadable_child?(kind, child, association)
240
240
  return false if kind == :initialize || kind == :find || kind == :touch
241
241
  return false if kind == :validate && association.validate?
@@ -15,7 +15,7 @@ module Mongoid
15
15
  #
16
16
  # @param [ Hash ] selector The MongoDB selector.
17
17
  #
18
- # @return [ true, false ] True if matches, false if not.
18
+ # @return [ true | false ] True if matches, false if not.
19
19
  def _matches?(selector)
20
20
  Matcher::Expression.matches?(self, selector)
21
21
  end
@@ -24,17 +24,22 @@ module Mongoid
24
24
  # an array of values of the `bar` field in each of the hashes in the
25
25
  # `foo` array.
26
26
  #
27
- # The return value is a two-element array. The first element is the value
28
- # retrieved, or an array of values. The second element is a boolean flag
29
- # indicating whether an array was expanded at any point during the key
30
- # traversal (because the respective document field was an array).
27
+ # This method can return an individual field value in some document
28
+ # or an array of values from multiple documents. The array can be returned
29
+ # because a field value in the specified path is an array of primitive
30
+ # values (e.g. integers) or because a field value in the specified path
31
+ # is an array of documents (e.g. a one-to-many embedded association),
32
+ # in which case the leaf value may be a scalar for each individual document.
33
+ # If the leaf value is an array and a one-to-many association was traversed,
34
+ # the return value will be an array of arrays. Note that an individual
35
+ # field value can also be an array and this case is indistinguishable
36
+ # from and behaves identically to association traversal for the purposes
37
+ # of, for example, subsequent array element retrieval.
31
38
  #
32
39
  # @param [ Document | Hash ] document The document to extract from.
33
40
  # @param [ String ] key The key path to extract.
34
41
  #
35
- # @return [ Array<true | false, Object | Array, true | false> ]
36
- # Whether the value existed in the document, the extracted value
37
- # and the array expansion flag.
42
+ # @return [ Object | Array ] Field value or values.
38
43
  module_function def extract_attribute(document, key)
39
44
  if document.respond_to?(:as_attributes, true)
40
45
  # If a document has hash fields, as_attributes would keep those fields
@@ -132,10 +132,10 @@ module Mongoid
132
132
  # @example Create multiple new documents.
133
133
  # Person.create({ title: "Mr" }, { title: "Mrs" })
134
134
  #
135
- # @param [ Hash, Array ] attributes The attributes to create with, or an
135
+ # @param [ Hash | Array ] attributes The attributes to create with, or an
136
136
  # Array of multiple attributes for multiple documents.
137
137
  #
138
- # @return [ Document, Array<Document> ] The newly created document(s).
138
+ # @return [ Document | Array<Document> ] The newly created document(s).
139
139
  def create(attributes = nil, &block)
140
140
  _creating do
141
141
  if attributes.is_a?(::Array)
@@ -159,10 +159,10 @@ module Mongoid
159
159
  # @example Create multiple new documents.
160
160
  # Person.create!({ title: "Mr" }, { title: "Mrs" })
161
161
  #
162
- # @param [ Hash, Array ] attributes The attributes to create with, or an
162
+ # @param [ Hash | Array ] attributes The attributes to create with, or an
163
163
  # Array of multiple attributes for multiple documents.
164
164
  #
165
- # @return [ Document, Array<Document> ] The newly created document(s).
165
+ # @return [ Document | Array<Document> ] The newly created document(s).
166
166
  def create!(attributes = nil, &block)
167
167
  _creating do
168
168
  if attributes.is_a?(::Array)
@@ -86,7 +86,7 @@ module Mongoid
86
86
  #
87
87
  # @param [ Hash ] options The delete options.
88
88
  #
89
- # @return [ true, false ] If the parent should be notified.
89
+ # @return [ true | false ] If the parent should be notified.
90
90
  def notifying_parent?(options = {})
91
91
  !options.delete(:suppress)
92
92
  end
@@ -14,7 +14,7 @@ module Mongoid
14
14
  #
15
15
  # @param [ Hash ] options Options to pass to destroy.
16
16
  #
17
- # @return [ true, false ] True if successful, false if not.
17
+ # @return [ true | false ] True if successful, false if not.
18
18
  def destroy(options = nil)
19
19
  raise Errors::ReadonlyDocument.new(self.class) if readonly?
20
20
  self.flagged_for_destroy = true
@@ -14,7 +14,7 @@ module Mongoid
14
14
  #
15
15
  # @param [ Hash ] options Options to pass to the save.
16
16
  #
17
- # @return [ true, false ] True is success, false if not.
17
+ # @return [ true | false ] True is success, false if not.
18
18
  def save(options = {})
19
19
  if new_record?
20
20
  !insert(options).new_record?
@@ -34,7 +34,7 @@ module Mongoid
34
34
  # @raise [ Errors::Validations ] If validation failed.
35
35
  # @raise [ Errors::Callback ] If a callback returns false.
36
36
  #
37
- # @return [ true, false ] True if validation passed.
37
+ # @return [ true | false ] True if validation passed.
38
38
  def save!(options = {})
39
39
  unless save(options)
40
40
  fail_due_to_validation! unless errors.empty?
@@ -13,7 +13,7 @@ module Mongoid
13
13
  # @example Unset the values.
14
14
  # document.unset(:first_name, :last_name, :middle)
15
15
  #
16
- # @param [ Array<String, Symbol> ] fields The names of the fields to
16
+ # @param [ Array<String | Symbol> ] fields The names of the fields to
17
17
  # unset.
18
18
  #
19
19
  # @return [ Document ] The document.
@@ -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