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
@@ -25,9 +25,9 @@ module Mongoid
25
25
  # @example Is the attribute present?
26
26
  # person.attribute_present?("title")
27
27
  #
28
- # @param [ String, Symbol ] name The name of the attribute.
28
+ # @param [ String | Symbol ] name The name of the attribute.
29
29
  #
30
- # @return [ true, false ] True if present, false if not.
30
+ # @return [ true | false ] True if present, false if not.
31
31
  def attribute_present?(name)
32
32
  attribute = read_raw_attribute(name)
33
33
  !attribute.blank? || attribute == false
@@ -50,9 +50,9 @@ module Mongoid
50
50
  # @example Does the document have the attribute?
51
51
  # model.has_attribute?(:name)
52
52
  #
53
- # @param [ String, Symbol ] name The name of the attribute.
53
+ # @param [ String | Symbol ] name The name of the attribute.
54
54
  #
55
- # @return [ true, false ] If the key is present in the attributes.
55
+ # @return [ true | false ] If the key is present in the attributes.
56
56
  def has_attribute?(name)
57
57
  attributes.key?(name.to_s)
58
58
  end
@@ -63,9 +63,9 @@ module Mongoid
63
63
  # @example Does the document have the attribute before it was assigned?
64
64
  # model.has_attribute_before_type_cast?(:name)
65
65
  #
66
- # @param [ String, Symbol ] name The name of the attribute.
66
+ # @param [ String | Symbol ] name The name of the attribute.
67
67
  #
68
- # @return [ true, false ] If the key is present in the
68
+ # @return [ true | false ] If the key is present in the
69
69
  # attributes_before_type_cast.
70
70
  def has_attribute_before_type_cast?(name)
71
71
  attributes_before_type_cast.key?(name.to_s)
@@ -80,7 +80,7 @@ module Mongoid
80
80
  # @example Read an attribute (alternate syntax.)
81
81
  # person[:title]
82
82
  #
83
- # @param [ String, Symbol ] name The name of the attribute to get.
83
+ # @param [ String | Symbol ] name The name of the attribute to get.
84
84
  #
85
85
  # @return [ Object ] The value of the attribute.
86
86
  def read_attribute(name)
@@ -113,7 +113,7 @@ module Mongoid
113
113
  # @example Read an attribute before type cast.
114
114
  # person.read_attribute_before_type_cast(:price)
115
115
  #
116
- # @param [ String, Symbol ] name The name of the attribute to get.
116
+ # @param [ String | Symbol ] name The name of the attribute to get.
117
117
  #
118
118
  # @return [ Object ] The value of the attribute before type cast, if
119
119
  # available. Otherwise, the value of the attribute.
@@ -132,7 +132,7 @@ module Mongoid
132
132
  # @example Remove the attribute.
133
133
  # person.remove_attribute(:title)
134
134
  #
135
- # @param [ String, Symbol ] name The name of the attribute to remove.
135
+ # @param [ String | Symbol ] name The name of the attribute to remove.
136
136
  #
137
137
  # @raise [ Errors::ReadonlyAttribute ] If the field cannot be removed due
138
138
  # to being flagged as reaodnly.
@@ -157,7 +157,7 @@ module Mongoid
157
157
  # @example Write the attribute (alternate syntax.)
158
158
  # person[:title] = "Mr."
159
159
  #
160
- # @param [ String, Symbol ] name The name of the attribute to update.
160
+ # @param [ String | Symbol ] name The name of the attribute to update.
161
161
  # @param [ Object ] value The value to set for the attribute.
162
162
  def write_attribute(name, value)
163
163
  validate_writable_field_name!(name.to_s)
@@ -237,7 +237,7 @@ module Mongoid
237
237
  #
238
238
  # @param [ String ] name The name of the attribute.
239
239
  #
240
- # @return [ true, false ] If the attribute is missing.
240
+ # @return [ true | false ] If the attribute is missing.
241
241
  def attribute_missing?(name)
242
242
  !Projector.new(__selected_fields).attribute_or_path_allowed?(name)
243
243
  end
@@ -261,7 +261,7 @@ module Mongoid
261
261
  # @example Is the string in dot syntax.
262
262
  # model.hash_dot_syntax?
263
263
  #
264
- # @return [ true, false ] If the string contains a "."
264
+ # @return [ true | false ] If the string contains a "."
265
265
  def hash_dot_syntax?(string)
266
266
  string.include?(".")
267
267
  end
@@ -271,7 +271,7 @@ module Mongoid
271
271
  # @example Get the value typecasted.
272
272
  # person.typed_value_for(:title, :sir)
273
273
  #
274
- # @param [ String, Symbol ] key The field name.
274
+ # @param [ String | Symbol ] key The field name.
275
275
  # @param [ Object ] value The uncast value.
276
276
  #
277
277
  # @return [ Object ] The cast value.
@@ -21,7 +21,7 @@ module Mongoid
21
21
  # @example Has the document changed?
22
22
  # model.changed?
23
23
  #
24
- # @return [ true, false ] If the document is changed.
24
+ # @return [ true | false ] If the document is changed.
25
25
  def changed?
26
26
  changes.values.any? { |val| val } || children_changed?
27
27
  end
@@ -30,7 +30,7 @@ module Mongoid
30
30
  #
31
31
  # @note This intentionally only considers children and not descendants.
32
32
  #
33
- # @return [ true, false ] If any children have changed.
33
+ # @return [ true | false ] If any children have changed.
34
34
  def children_changed?
35
35
  _children.any?(&:changed?)
36
36
  end
@@ -102,7 +102,7 @@ module Mongoid
102
102
  # @example Remove a flagged change.
103
103
  # model.remove_change(:field)
104
104
  #
105
- # @param [ Symbol, String ] name The name of the field.
105
+ # @param [ Symbol | String ] name The name of the field.
106
106
  def remove_change(name)
107
107
  changed_attributes.delete(name.to_s)
108
108
  end
@@ -162,7 +162,7 @@ module Mongoid
162
162
  #
163
163
  # @param [ String ] attr The name of the attribute.
164
164
  #
165
- # @return [ true, false ] Whether the attribute has changed.
165
+ # @return [ true | false ] Whether the attribute has changed.
166
166
  def attribute_changed?(attr)
167
167
  attr = database_field_name(attr)
168
168
  return false unless changed_attributes.key?(attr)
@@ -176,7 +176,7 @@ module Mongoid
176
176
  #
177
177
  # @param [ String ] attr The name of the attribute.
178
178
  #
179
- # @return [ true, false ] If the attribute differs.
179
+ # @return [ true | false ] If the attribute differs.
180
180
  def attribute_changed_from_default?(attr)
181
181
  field = fields[attr]
182
182
  return false unless field
@@ -12,7 +12,7 @@ module Mongoid
12
12
  # m.save
13
13
  # end
14
14
  #
15
- # @param [ Hash, Mongoid::PersistenceContext ] options_or_context
15
+ # @param [ Hash | Mongoid::PersistenceContext ] options_or_context
16
16
  # The storage options or a persistence context.
17
17
  #
18
18
  # @option options [ String | Symbol ] :collection The collection name.
@@ -17,7 +17,7 @@ module Mongoid
17
17
  # Storage.validate(:collection_name)
18
18
  #
19
19
  # @param [ Class ] klass The model class.
20
- # @param [ Hash, String, Symbol ] options The provided options.
20
+ # @param [ Hash | String | Symbol ] options The provided options.
21
21
  def validate(klass, options)
22
22
  valid_keys?(options) or raise Errors::InvalidStorageOptions.new(klass, options)
23
23
  valid_parent?(klass) or raise Errors::InvalidStorageParent.new(klass)
@@ -31,7 +31,7 @@ module Mongoid
31
31
  #
32
32
  # @param [ Class ] klass
33
33
  #
34
- # @return [ true, false ] If the class is valid
34
+ # @return [ true | false ] If the class is valid.
35
35
  def valid_parent?(klass)
36
36
  !klass.superclass.include?(Mongoid::Document)
37
37
  end
@@ -45,7 +45,7 @@ module Mongoid
45
45
  #
46
46
  # @param [ Hash ] options The options hash.
47
47
  #
48
- # @return [ true, false ] If all keys are valid.
48
+ # @return [ true | false ] If all keys are valid.
49
49
  def valid_keys?(options)
50
50
  return false unless options.is_a?(::Hash)
51
51
  options.keys.all? do |key|
@@ -37,7 +37,7 @@ module Mongoid
37
37
  # @example Validate the client has database.
38
38
  # validator.validate_client_database(:default, {})
39
39
  #
40
- # @param [ String, Symbol ] name The config key.
40
+ # @param [ String | Symbol ] name The config key.
41
41
  # @param [ Hash ] config The configuration.
42
42
  def validate_client_database(name, config)
43
43
  if no_database_or_uri?(config)
@@ -52,7 +52,7 @@ module Mongoid
52
52
  # @example Validate the client has hosts.
53
53
  # validator.validate_client_hosts(:default, {})
54
54
  #
55
- # @param [ String, Symbol ] name The config key.
55
+ # @param [ String | Symbol ] name The config key.
56
56
  # @param [ Hash ] config The configuration.
57
57
  def validate_client_hosts(name, config)
58
58
  if no_hosts_or_uri?(config)
@@ -68,7 +68,7 @@ module Mongoid
68
68
  # @example Validate the uri and options.
69
69
  # validator.validate_client_uri(:default, {})
70
70
  #
71
- # @param [ String, Symbol ] name The config key.
71
+ # @param [ String | Symbol ] name The config key.
72
72
  # @param [ Hash ] config The configuration.
73
73
  def validate_client_uri(name, config)
74
74
  if both_uri_and_standard?(config)
@@ -86,7 +86,7 @@ module Mongoid
86
86
  #
87
87
  # @param [ Hash ] config The configuration options.
88
88
  #
89
- # @return [ true, false ] If no database or uri is defined.
89
+ # @return [ true | false ] If no database or uri is defined.
90
90
  def no_database_or_uri?(config)
91
91
  !config.has_key?(:database) && !config.has_key?(:uri)
92
92
  end
@@ -101,7 +101,7 @@ module Mongoid
101
101
  #
102
102
  # @param [ Hash ] config The configuration options.
103
103
  #
104
- # @return [ true, false ] If no hosts or uri is defined.
104
+ # @return [ true | false ] If no hosts or uri is defined.
105
105
  def no_hosts_or_uri?(config)
106
106
  !config.has_key?(:hosts) && !config.has_key?(:uri)
107
107
  end
@@ -116,7 +116,7 @@ module Mongoid
116
116
  #
117
117
  # @param [ Hash ] config The configuration options.
118
118
  #
119
- # @return [ true, false ] If both standard and uri are defined.
119
+ # @return [ true | false ] If both standard and uri are defined.
120
120
  def both_uri_and_standard?(config)
121
121
  config.has_key?(:uri) && config.keys.any? do |key|
122
122
  STANDARD.include?(key.to_sym)
@@ -131,7 +131,7 @@ module Mongoid
131
131
  # @example Is Mongoid configured?
132
132
  # config.configured?
133
133
  #
134
- # @return [ true, false ] If Mongoid is configured.
134
+ # @return [ true | false ] If Mongoid is configured.
135
135
  def configured?
136
136
  clients.key?(:default)
137
137
  end
@@ -172,7 +172,7 @@ module Mongoid
172
172
  # Mongoid.load!("/path/to/mongoid.yml")
173
173
  #
174
174
  # @param [ String ] path The path to the file.
175
- # @param [ String, Symbol ] environment The environment to load.
175
+ # @param [ String | Symbol ] environment The environment to load.
176
176
  def load!(path, environment = nil)
177
177
  settings = Environment.load_yaml(path, environment)
178
178
  if settings.present?
@@ -225,9 +225,9 @@ module Mongoid
225
225
  # @example Override the database globally.
226
226
  # config.override_database(:optional)
227
227
  #
228
- # @param [ String, Symbol ] name The name of the database.
228
+ # @param [ String | Symbol ] name The name of the database.
229
229
  #
230
- # @return [ String, Symbol ] The global override.
230
+ # @return [ String | Symbol ] The global override.
231
231
  def override_database(name)
232
232
  Threaded.database_override = name
233
233
  end
@@ -237,9 +237,9 @@ module Mongoid
237
237
  # @example Override the client globally.
238
238
  # config.override_client(:optional)
239
239
  #
240
- # @param [ String, Symbol ] name The name of the client.
240
+ # @param [ String | Symbol ] name The name of the client.
241
241
  #
242
- # @return [ String, Symbol ] The global override.
242
+ # @return [ String | Symbol ] The global override.
243
243
  def override_client(name)
244
244
  Threaded.client_override = name ? name.to_s : nil
245
245
  end
@@ -310,7 +310,7 @@ module Mongoid
310
310
  # @example Is the application using passenger?
311
311
  # config.running_with_passenger?
312
312
  #
313
- # @return [ true, false ] If the app is deployed on Passenger.
313
+ # @return [ true | false ] If the app is deployed on Passenger.
314
314
  def running_with_passenger?
315
315
  @running_with_passenger ||= defined?(PhusionPassenger)
316
316
  end
@@ -9,7 +9,7 @@ module Mongoid
9
9
  # Get all the aggregate values for the provided field.
10
10
  # Provided for interface consistency with Aggregable::Mongo.
11
11
  #
12
- # @param [ String, Symbol ] field The field name.
12
+ # @param [ String | Symbol ] field The field name.
13
13
  #
14
14
  # @return [ Hash ] A Hash containing the aggregate values.
15
15
  # If no documents are present, then returned Hash will have
@@ -20,7 +20,7 @@ module Mongoid
20
20
  # # "avg" => 750.0
21
21
  # # }
22
22
  #
23
- # @param [ String, Symbol ] field The field name.
23
+ # @param [ String | Symbol ] field The field name.
24
24
  #
25
25
  # @return [ Hash ] A Hash containing the aggregate values.
26
26
  # If no documents are found, then returned Hash will have
@@ -64,7 +64,7 @@ module Mongoid
64
64
  #
65
65
  # @param [ Symbol ] field The field to max.
66
66
  #
67
- # @return [ Float, Document ] The max value or document with the max
67
+ # @return [ Float | Document ] The max value or document with the max
68
68
  # value.
69
69
  def max(field = nil)
70
70
  block_given? ? super() : aggregates(field)["max"]
@@ -84,7 +84,7 @@ module Mongoid
84
84
  #
85
85
  # @param [ Symbol ] field The field to min.
86
86
  #
87
- # @return [ Float, Document ] The min value or document with the min
87
+ # @return [ Float | Document ] The min value or document with the min
88
88
  # value.
89
89
  def min(field = nil)
90
90
  block_given? ? super() : aggregates(field)["min"]
@@ -115,7 +115,7 @@ module Mongoid
115
115
  # @example Get the pipeline.
116
116
  # aggregable.pipeline(:likes)
117
117
  #
118
- # @param [ String, Symbol ] field The name of the field.
118
+ # @param [ String | Symbol ] field The name of the field.
119
119
  #
120
120
  # @return [ Array ] The array of pipeline operators.
121
121
  def pipeline(field)
@@ -11,7 +11,7 @@ module Mongoid
11
11
  # Get all the aggregate values for the provided field in null context.
12
12
  # Provided for interface consistency with Aggregable::Mongo.
13
13
  #
14
- # @param [ String, Symbol ] _field The field name.
14
+ # @param [ String | Symbol ] _field The field name.
15
15
  #
16
16
  # @return [ Hash ] A Hash with count, sum of 0 and max, min, avg of nil.
17
17
  def aggregates(_field)
@@ -150,7 +150,7 @@ module Mongoid
150
150
  # @example Unset the field on the matches.
151
151
  # context.unset(:name)
152
152
  #
153
- # @param [ String | Symbol | Array<String|Symbol> | Hash ] args
153
+ # @param [ String | Symbol | Array<String | Symbol> | Hash ] args
154
154
  # The name(s) of the field(s) to unset.
155
155
  # If a Hash is specified, its keys will be used irrespective of what
156
156
  # each key's value is, even if the value is nil or false.
@@ -16,7 +16,7 @@ module Mongoid
16
16
  # @example Get the average distance.
17
17
  # geo_near.average_distance
18
18
  #
19
- # @return [ Float, nil ] The average distance.
19
+ # @return [ Float | nil ] The average distance.
20
20
  def average_distance
21
21
  average = stats["avgDistance"]
22
22
  (average.nil? || average.nan?) ? nil : average
@@ -46,7 +46,7 @@ module Mongoid
46
46
  # @example Provide the distance multiplier.
47
47
  # geo_near.distance_multiplier(13113.1)
48
48
  #
49
- # @param [ Integer, Float ] value The distance multiplier.
49
+ # @param [ Integer | Float ] value The distance multiplier.
50
50
  #
51
51
  # @return [ GeoNear ] The GeoNear wrapper.
52
52
  def distance_multiplier(value)
@@ -98,9 +98,9 @@ module Mongoid
98
98
  # @example Get the max distance.
99
99
  # geo_near.max_distance
100
100
  #
101
- # @param [ Integer, Float ] value The maximum distance.
101
+ # @param [ Integer | Float ] value The maximum distance.
102
102
  #
103
- # @return [ GeoNear, Float ] The GeoNear command or the value.
103
+ # @return [ GeoNear | Float ] The GeoNear command or the value.
104
104
  def max_distance(value = nil)
105
105
  if value
106
106
  command[:maxDistance] = value
@@ -115,7 +115,7 @@ module Mongoid
115
115
  # @example Set the min distance.
116
116
  # geo_near.min_distance(0.5)
117
117
  #
118
- # @param [ Integer, Float ] value The minimum distance.
118
+ # @param [ Integer | Float ] value The minimum distance.
119
119
  #
120
120
  # @return [ GeoNear ] The GeoNear command.
121
121
  def min_distance(value)
@@ -139,7 +139,7 @@ module Mongoid
139
139
  # @example Set the unique flag.
140
140
  # geo_near.unique(false)
141
141
  #
142
- # @param [ true, false ] value Whether to return unique documents.
142
+ # @param [ true | false ] value Whether to return unique documents.
143
143
  #
144
144
  # @return [ GeoNear ] The command.
145
145
  def unique(value = true)
@@ -211,7 +211,7 @@ module Mongoid
211
211
  # @example Get the documents.
212
212
  # geo_near.documents
213
213
  #
214
- # @return [ Array, Cursor ] The documents.
214
+ # @return [ Array | Cursor ] The documents.
215
215
  def documents
216
216
  results["results"].map do |attributes|
217
217
  doc = Factory.from_db(criteria.klass, attributes["obj"], criteria)
@@ -25,7 +25,7 @@ module Mongoid
25
25
  #
26
26
  # @param [ Array ] other The other array.
27
27
  #
28
- # @return [ true, false ] If the objects are equal.
28
+ # @return [ true | false ] If the objects are equal.
29
29
  def ==(other)
30
30
  return false unless other.respond_to?(:entries)
31
31
  entries == other.entries
@@ -110,7 +110,7 @@ module Mongoid
110
110
  # @example Do any documents exist for the context.
111
111
  # context.exists?
112
112
  #
113
- # @return [ true, false ] If the count is more than zero.
113
+ # @return [ true | false ] If the count is more than zero.
114
114
  def exists?
115
115
  any?
116
116
  end
@@ -244,7 +244,7 @@ module Mongoid
244
244
  #
245
245
  # @param [ String | Symbol ] *fields Field(s) to pluck.
246
246
  #
247
- # @return [ Array ] The array of plucked values.
247
+ # @return [ Array<Object> | Array<Array<Object>> ] The plucked values.
248
248
  def pluck(*fields)
249
249
  if Mongoid.legacy_pluck_distinct
250
250
  documents.pluck(*fields)
@@ -318,7 +318,7 @@ module Mongoid
318
318
  #
319
319
  # @param [ Hash ] attributes The new attributes for the document.
320
320
  #
321
- # @return [ nil, false ] False if no attributes were provided.
321
+ # @return [ nil | false ] False if no attributes were provided.
322
322
  def update(attributes = nil)
323
323
  update_documents(attributes, [ first ])
324
324
  end
@@ -330,7 +330,7 @@ module Mongoid
330
330
  #
331
331
  # @param [ Hash ] attributes The new attributes for each document.
332
332
  #
333
- # @return [ nil, false ] False if no attributes were provided.
333
+ # @return [ nil | false ] False if no attributes were provided.
334
334
  def update_all(attributes = nil)
335
335
  update_documents(attributes, entries)
336
336
  end
@@ -109,7 +109,7 @@ module Mongoid
109
109
  # @example Get the distinct values.
110
110
  # context.distinct(:name)
111
111
  #
112
- # @param [ String, Symbol ] field The name of the field.
112
+ # @param [ String | Symbol ] field The name of the field.
113
113
  #
114
114
  # @return [ Array<Object> ] The distinct values for the field.
115
115
  def distinct(field)
@@ -157,7 +157,7 @@ module Mongoid
157
157
  # @note We don't use count here since Mongo does not use counted
158
158
  # b-tree indexes.
159
159
  #
160
- # @return [ true, false ] If the count is more than zero.
160
+ # @return [ true | false ] If the count is more than zero.
161
161
  def exists?
162
162
  !!(view.projection(_id: 1).limit(1).first)
163
163
  end
@@ -181,9 +181,9 @@ module Mongoid
181
181
  # @param [ Hash ] update The updates.
182
182
  # @param [ Hash ] options The command options.
183
183
  #
184
- # @option options [ :before, :after ] :return_document Return the updated document
184
+ # @option options [ :before | :after ] :return_document Return the updated document
185
185
  # from before or after update.
186
- # @option options [ true, false ] :upsert Create the document if it doesn't exist.
186
+ # @option options [ true | false ] :upsert Create the document if it doesn't exist.
187
187
  #
188
188
  # @return [ Document ] The result of the command.
189
189
  def find_one_and_update(update, options = {})
@@ -201,9 +201,9 @@ module Mongoid
201
201
  # @param [ Hash ] replacement The replacement.
202
202
  # @param [ Hash ] options The command options.
203
203
  #
204
- # @option options [ :before, :after ] :return_document Return the updated document
204
+ # @option options [ :before | :after ] :return_document Return the updated document
205
205
  # from before or after update.
206
- # @option options [ true, false ] :upsert Create the document if it doesn't exist.
206
+ # @option options [ true | false ] :upsert Create the document if it doesn't exist.
207
207
  #
208
208
  # @return [ Document ] The result of the command.
209
209
  def find_one_and_replace(replacement, options = {})
@@ -397,9 +397,9 @@ module Mongoid
397
397
  # @example Pluck a field.
398
398
  # context.pluck(:_id)
399
399
  #
400
- # @param [ String, Symbol, Array ] fields Fields to pluck.
400
+ # @param [ String | Symbol ] *fields Field(s) to pluck.
401
401
  #
402
- # @return [ Array<Object, Array> ] The plucked values.
402
+ # @return [ Array<Object> | Array<Array<Object>> ] The plucked values.
403
403
  def pluck(*fields)
404
404
  # Multiple fields can map to the same field name. For example, plucking
405
405
  # a field and its _translations field map to the same field in the database.
@@ -434,9 +434,9 @@ module Mongoid
434
434
  # @example Pick a field.
435
435
  # context.pick(:_id)
436
436
  #
437
- # @param [ String, Symbol, Array ] fields Fields to pick.
437
+ # @param [ String | Symbol ] *fields Field(s) to pick.
438
438
  #
439
- # @return [ Object, Array<Object> ] The picked values.
439
+ # @return [ Object | Array<Object> ] The picked values.
440
440
  def pick(*fields)
441
441
  limit(1).pluck(*fields).first
442
442
  end
@@ -586,7 +586,7 @@ module Mongoid
586
586
  # @param [ Hash ] attributes The updates.
587
587
  # @param [ Symbol ] method The method to use.
588
588
  #
589
- # @return [ true, false ] If the update succeeded.
589
+ # @return [ true | false ] If the update succeeded.
590
590
  def update_documents(attributes, method = :update_one, opts = {})
591
591
  return false unless attributes
592
592
  attributes = Hash[attributes.map { |k, v| [klass.database_field_name(k.to_s), v] }]
@@ -654,7 +654,7 @@ module Mongoid
654
654
  # @example Get the documents for iteration.
655
655
  # context.documents_for_iteration
656
656
  #
657
- # @return [ Array<Document>, Mongo::Collection::View ] The docs to iterate.
657
+ # @return [ Array<Document> | Mongo::Collection::View ] The docs to iterate.
658
658
  def documents_for_iteration
659
659
  return view unless eager_loadable?
660
660
  docs = view.map{ |doc| Factory.from_db(klass, doc, criteria) }
@@ -764,7 +764,7 @@ module Mongoid
764
764
  #
765
765
  # @param [ String ] field_name The name of the field to demongoize.
766
766
  # @param [ Object ] value The value to demongoize.
767
- # @param [ Boolean ] is_translation The field we are retrieving is an
767
+ # @param [ true | false ] is_translation The field we are retrieving is an
768
768
  # _translations field.
769
769
  #
770
770
  # @return [ Object ] The demongoized value.
@@ -778,7 +778,7 @@ module Mongoid
778
778
  #
779
779
  # @param [ Field ] field The field to use to demongoize.
780
780
  # @param [ Object ] value The value to demongoize.
781
- # @param [ Boolean ] is_translation The field we are retrieving is an
781
+ # @param [ true | false ] is_translation The field we are retrieving is an
782
782
  # _translations field.
783
783
  #
784
784
  # @return [ Object ] The demongoized value.
@@ -40,7 +40,7 @@ module Mongoid
40
40
  #
41
41
  # @param [ Array ] other The other array.
42
42
  #
43
- # @return [ true, false ] If the objects are equal.
43
+ # @return [ true | false ] If the objects are equal.
44
44
  def ==(other)
45
45
  other.is_a?(None)
46
46
  end
@@ -88,7 +88,7 @@ module Mongoid
88
88
  # @example Get the values for null context.
89
89
  # context.pluck(:name)
90
90
  #
91
- # @param [ String | Symbol ] *_fields Field or fields to pluck.
91
+ # @param [ String | Symbol ] *_fields Field(s) to pluck.
92
92
  #
93
93
  # @return [ Array ] An empty Array.
94
94
  def pluck(*_fields)
@@ -14,7 +14,7 @@ module Mongoid
14
14
  # @example Is the context empty?
15
15
  # context.blank?
16
16
  #
17
- # @return [ true, false ] If the context is empty.
17
+ # @return [ true | false ] If the context is empty.
18
18
  def blank?
19
19
  !exists?
20
20
  end
@@ -30,7 +30,7 @@ module Mongoid
30
30
  # @example Get the context.
31
31
  # criteria.context
32
32
  #
33
- # @return [ Memory, Mongo ] The context.
33
+ # @return [ Memory | Mongo ] The context.
34
34
  def context
35
35
  @context ||= create_context
36
36
  end
@@ -45,7 +45,7 @@ module Mongoid
45
45
  # @example Create the context.
46
46
  # contextual.create_context
47
47
  #
48
- # @return [ Mongo, Memory ] The context.
48
+ # @return [ Mongo | Memory ] The context.
49
49
  def create_context
50
50
  return None.new(self) if empty_and_chainable?
51
51
  embedded ? Memory.new(self) : Mongo.new(self)
@@ -10,11 +10,11 @@ module Mongoid
10
10
  # criteria.execute_or_raise(id)
11
11
  #
12
12
  # @param [ Object ] ids The arguments passed.
13
- # @param [ true, false ] multi Whether there arguments were a list.
13
+ # @param [ true | false ] multi Whether there arguments were a list.
14
14
  #
15
15
  # @raise [ Errors::DocumentNotFound ] If nothing returned.
16
16
  #
17
- # @return [ Document, Array<Document> ] The document(s).
17
+ # @return [ Document | Array<Document> ] The document(s).
18
18
  def execute_or_raise(ids, multi)
19
19
  result = multiple_from_db(ids)
20
20
  check_for_missing_documents!(result, ids)
@@ -23,15 +23,18 @@ module Mongoid
23
23
 
24
24
  # Find the matchind document(s) in the criteria for the provided ids.
25
25
  #
26
+ # @note Each argument can be an individual id, an array of ids or
27
+ # a nested array. Each array will be flattened.
28
+ #
26
29
  # @example Find by an id.
27
30
  # criteria.find(BSON::ObjectId.new)
28
31
  #
29
32
  # @example Find by multiple ids.
30
33
  # criteria.find([ BSON::ObjectId.new, BSON::ObjectId.new ])
31
34
  #
32
- # @param [ Array<BSON::ObjectId> ] args The ids to search for.
35
+ # @param [ Object | Array<Object> ] *args The ids to search for.
33
36
  #
34
- # @return [ Array<Document>, Document ] The matching document(s).
37
+ # @return [ Document | Array<Document> ] The matching document(s).
35
38
  def find(*args)
36
39
  ids = args.__find_args__
37
40
  raise_invalid if ids.any?(&:nil?)
@@ -66,7 +66,7 @@ module Mongoid
66
66
 
67
67
  # Iterate through the list of relations and create the inclusions list.
68
68
  #
69
- # @param [ Class, String, Symbol ] _parent_class The class from which the
69
+ # @param [ Class | String | Symbol ] _parent_class The class from which the
70
70
  # association originates.
71
71
  # @param [ String ] parent The name of the association above this one in
72
72
  # the inclusion tree, if it is a nested inclusion.
@@ -54,7 +54,7 @@ module Mongoid
54
54
  # @api private
55
55
  #
56
56
  # @param [ Object ] criteria
57
- # @return [ Boolean ] if should permit
57
+ # @return [ true | false ] if should permit
58
58
  def should_permit?(criteria)
59
59
  if criteria.respond_to?(:permitted?)
60
60
  return criteria.permitted?