mongoid 8.0.13 → 8.1.0

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 (225) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +3 -3
  4. data/README.md +3 -3
  5. data/Rakefile +17 -66
  6. data/lib/config/locales/en.yml +46 -40
  7. data/lib/mongoid/association/accessors.rb +3 -7
  8. data/lib/mongoid/association/builders.rb +1 -1
  9. data/lib/mongoid/association/depending.rb +4 -8
  10. data/lib/mongoid/association/eager_loadable.rb +0 -3
  11. data/lib/mongoid/association/embedded/batchable.rb +2 -2
  12. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  13. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
  14. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
  15. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
  16. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
  17. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
  18. data/lib/mongoid/association/macros.rb +0 -6
  19. data/lib/mongoid/association/nested/many.rb +3 -38
  20. data/lib/mongoid/association/nested/nested_buildable.rb +0 -14
  21. data/lib/mongoid/association/nested/one.rb +40 -2
  22. data/lib/mongoid/association/proxy.rb +1 -1
  23. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  24. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  25. data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
  26. data/lib/mongoid/association/referenced/has_many/proxy.rb +4 -103
  27. data/lib/mongoid/association/reflections.rb +2 -2
  28. data/lib/mongoid/atomic.rb +7 -16
  29. data/lib/mongoid/attributes/dynamic.rb +1 -1
  30. data/lib/mongoid/attributes/nested.rb +2 -2
  31. data/lib/mongoid/attributes/processing.rb +5 -29
  32. data/lib/mongoid/attributes/projector.rb +1 -1
  33. data/lib/mongoid/attributes/readonly.rb +1 -1
  34. data/lib/mongoid/attributes.rb +8 -2
  35. data/lib/mongoid/changeable.rb +107 -5
  36. data/lib/mongoid/clients/factory.rb +0 -4
  37. data/lib/mongoid/clients/storage_options.rb +2 -5
  38. data/lib/mongoid/clients/validators/storage.rb +1 -13
  39. data/lib/mongoid/collection_configurable.rb +58 -0
  40. data/lib/mongoid/composable.rb +2 -0
  41. data/lib/mongoid/config/defaults.rb +60 -0
  42. data/lib/mongoid/config/options.rb +0 -3
  43. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  44. data/lib/mongoid/config/validators.rb +1 -0
  45. data/lib/mongoid/config.rb +88 -89
  46. data/lib/mongoid/contextual/aggregable/memory.rb +2 -5
  47. data/lib/mongoid/contextual/atomic.rb +1 -1
  48. data/lib/mongoid/contextual/memory.rb +240 -51
  49. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  50. data/lib/mongoid/contextual/mongo.rb +370 -133
  51. data/lib/mongoid/contextual/none.rb +162 -7
  52. data/lib/mongoid/contextual.rb +12 -0
  53. data/lib/mongoid/criteria/findable.rb +2 -2
  54. data/lib/mongoid/criteria/includable.rb +4 -3
  55. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
  56. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  57. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -13
  58. data/lib/mongoid/criteria/queryable/optional.rb +8 -8
  59. data/lib/mongoid/criteria/queryable/selectable.rb +43 -121
  60. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  61. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  62. data/lib/mongoid/criteria.rb +6 -5
  63. data/lib/mongoid/deprecable.rb +1 -2
  64. data/lib/mongoid/deprecation.rb +3 -3
  65. data/lib/mongoid/document.rb +1 -8
  66. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  67. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  68. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  69. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  70. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  71. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  72. data/lib/mongoid/errors.rb +4 -2
  73. data/lib/mongoid/extensions/hash.rb +3 -51
  74. data/lib/mongoid/extensions/object.rb +2 -2
  75. data/lib/mongoid/extensions/time.rb +2 -0
  76. data/lib/mongoid/fields/localized.rb +10 -0
  77. data/lib/mongoid/fields/standard.rb +10 -0
  78. data/lib/mongoid/fields.rb +59 -35
  79. data/lib/mongoid/findable.rb +27 -3
  80. data/lib/mongoid/interceptable.rb +6 -116
  81. data/lib/mongoid/matchable.rb +1 -6
  82. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  83. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +5 -3
  84. data/lib/mongoid/matcher/regex.rb +9 -8
  85. data/lib/mongoid/matcher/type.rb +1 -1
  86. data/lib/mongoid/matcher.rb +0 -1
  87. data/lib/mongoid/persistable/creatable.rb +1 -0
  88. data/lib/mongoid/persistable/deletable.rb +1 -1
  89. data/lib/mongoid/persistable/savable.rb +13 -1
  90. data/lib/mongoid/persistable/unsettable.rb +2 -2
  91. data/lib/mongoid/persistable/updatable.rb +51 -1
  92. data/lib/mongoid/persistable/upsertable.rb +20 -1
  93. data/lib/mongoid/persistable.rb +3 -0
  94. data/lib/mongoid/query_cache.rb +5 -1
  95. data/lib/mongoid/railties/database.rake +7 -2
  96. data/lib/mongoid/reloadable.rb +5 -3
  97. data/lib/mongoid/stateful.rb +22 -1
  98. data/lib/mongoid/tasks/database.rake +12 -0
  99. data/lib/mongoid/tasks/database.rb +20 -0
  100. data/lib/mongoid/threaded.rb +0 -3
  101. data/lib/mongoid/timestamps/created.rb +1 -8
  102. data/lib/mongoid/traversable.rb +0 -12
  103. data/lib/mongoid/utils.rb +22 -0
  104. data/lib/mongoid/validatable/associated.rb +17 -98
  105. data/lib/mongoid/validatable/macros.rb +5 -20
  106. data/lib/mongoid/validatable.rb +4 -10
  107. data/lib/mongoid/version.rb +1 -5
  108. data/lib/mongoid/warnings.rb +17 -2
  109. data/lib/mongoid.rb +16 -3
  110. data/spec/integration/app_spec.rb +2 -20
  111. data/spec/integration/associations/embeds_one_spec.rb +5 -25
  112. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -55
  113. data/spec/integration/callbacks_spec.rb +99 -12
  114. data/spec/integration/discriminator_key_spec.rb +4 -5
  115. data/spec/integration/dots_and_dollars_spec.rb +2 -12
  116. data/spec/integration/i18n_fallbacks_spec.rb +3 -2
  117. data/spec/integration/matcher_operator_data/regex.yml +0 -21
  118. data/spec/mongoid/association/eager_spec.rb +2 -24
  119. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
  120. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
  121. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  122. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
  123. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  124. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
  125. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +42 -103
  126. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -195
  127. data/spec/mongoid/association/syncable_spec.rb +1 -1
  128. data/spec/mongoid/attributes/nested_spec.rb +10 -204
  129. data/spec/mongoid/attributes_spec.rb +3 -33
  130. data/spec/mongoid/changeable_spec.rb +299 -24
  131. data/spec/mongoid/clients/factory_spec.rb +0 -30
  132. data/spec/mongoid/clients_spec.rb +122 -13
  133. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  134. data/spec/mongoid/config/defaults_spec.rb +160 -0
  135. data/spec/mongoid/config_spec.rb +154 -27
  136. data/spec/mongoid/contextual/aggregable/memory_spec.rb +0 -91
  137. data/spec/mongoid/contextual/memory_spec.rb +332 -253
  138. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  139. data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
  140. data/spec/mongoid/contextual/none_spec.rb +49 -2
  141. data/spec/mongoid/copyable_spec.rb +2 -10
  142. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
  143. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  144. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -2
  145. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
  146. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +0 -235
  147. data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
  148. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  149. data/spec/mongoid/criteria_projection_spec.rb +1 -4
  150. data/spec/mongoid/criteria_spec.rb +5 -11
  151. data/spec/mongoid/document_spec.rb +0 -27
  152. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  153. data/spec/mongoid/extensions/hash_spec.rb +3 -239
  154. data/spec/mongoid/extensions/time_spec.rb +8 -43
  155. data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
  156. data/spec/mongoid/fields/localized_spec.rb +46 -28
  157. data/spec/mongoid/fields_spec.rb +136 -77
  158. data/spec/mongoid/findable_spec.rb +391 -34
  159. data/spec/mongoid/indexable_spec.rb +16 -10
  160. data/spec/mongoid/interceptable_spec.rb +153 -442
  161. data/spec/mongoid/interceptable_spec_models.rb +111 -51
  162. data/spec/mongoid/persistable/deletable_spec.rb +26 -6
  163. data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
  164. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  165. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  166. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  167. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  168. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  169. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  170. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  171. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  172. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  173. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  174. data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
  175. data/spec/mongoid/persistence_context_spec.rb +7 -57
  176. data/spec/mongoid/query_cache_spec.rb +56 -61
  177. data/spec/mongoid/reloadable_spec.rb +24 -28
  178. data/spec/mongoid/scopable_spec.rb +70 -0
  179. data/spec/mongoid/serializable_spec.rb +23 -44
  180. data/spec/mongoid/stateful_spec.rb +122 -8
  181. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  182. data/spec/mongoid/tasks/database_spec.rb +127 -0
  183. data/spec/mongoid/timestamps/created_spec.rb +0 -23
  184. data/spec/mongoid/timestamps_spec.rb +9 -11
  185. data/spec/mongoid/touchable_spec.rb +277 -5
  186. data/spec/mongoid/touchable_spec_models.rb +3 -1
  187. data/spec/mongoid/traversable_spec.rb +9 -24
  188. data/spec/mongoid/validatable/associated_spec.rb +34 -27
  189. data/spec/mongoid/validatable/numericality_spec.rb +0 -16
  190. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
  191. data/spec/mongoid_spec.rb +36 -10
  192. data/spec/shared/lib/mrss/docker_runner.rb +1 -1
  193. data/spec/shared/lib/mrss/server_version_registry.rb +1 -1
  194. data/spec/shared/lib/mrss/spec_organizer.rb +3 -32
  195. data/spec/shared/share/Dockerfile.erb +85 -15
  196. data/spec/shared/shlib/distro.sh +0 -10
  197. data/spec/shared/shlib/server.sh +27 -34
  198. data/spec/shared/shlib/set_env.sh +68 -9
  199. data/spec/spec_helper.rb +5 -0
  200. data/spec/support/expectations.rb +17 -20
  201. data/spec/support/immutable_ids.rb +118 -0
  202. data/spec/support/macros.rb +47 -15
  203. data/spec/support/models/artist.rb +0 -1
  204. data/spec/support/models/band.rb +1 -0
  205. data/spec/support/models/building.rb +2 -0
  206. data/spec/support/models/name.rb +0 -10
  207. data/spec/support/models/person.rb +0 -1
  208. data/spec/support/models/product.rb +1 -0
  209. data.tar.gz.sig +0 -0
  210. metadata +715 -671
  211. metadata.gz.sig +2 -0
  212. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
  213. data/lib/mongoid/field_readable.rb +0 -70
  214. data/lib/mongoid/matcher/regexp_budget.rb +0 -389
  215. data/lib/mongoid/validatable/numericality.rb +0 -19
  216. data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
  217. data/spec/integration/query_operator_guard_spec.rb +0 -89
  218. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -61
  219. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -61
  220. data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
  221. data/spec/shared/CANDIDATE.md +0 -28
  222. data/spec/shared/lib/mrss/release/candidate.rb +0 -281
  223. data/spec/shared/lib/mrss/release/product_data.rb +0 -144
  224. data/spec/shared/lib/tasks/candidate.rake +0 -64
  225. data/spec/support/models/purse.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9945b53ebb2236e5b44ef4cfead09b790b3b00881f62dba5c7007c1d99fdcba
4
- data.tar.gz: f092a211395767e35a20bd2492e9c9be56c3bc53721bb6e8b437c0ef4d4c3111
3
+ metadata.gz: 1f5f0b81e26dba41d786804bd1213f2c05c4594ca9e05d0f62417fc15da6532e
4
+ data.tar.gz: c44f03a981d2fc648822718522e2ee7e8db6fa3fec01764eb09d77a4183a3559
5
5
  SHA512:
6
- metadata.gz: 7fa47f5a3a012f20238d7813bc173c3a22b0f96e493bb391fc5d5d4cb5ffc37d50bd27959f2fa871f11b402ef739d43ab3ff044a7cd256ef4531b340bf1f882d
7
- data.tar.gz: 8bf1abb2f757cb18b92ccfae1214a7d19c6d6331e2ed30a4a39068eab365e8cf4cd0fc017810029106a4823ddb8a8a416a63de4faa334332e012f403167b7351
6
+ metadata.gz: bafd2e708f204e23b0e277df74f897d19a83f059eb34bff3b636231f6e76a83176a45ea1b49586bff52c44bc3a526bd0d988cec3441bc469514035ad0acc7272
7
+ data.tar.gz: 59e6b77e3e03d94cb82fd2aad20c3951cbcc9f0872138ae76f6837986aad641cce339d5d51b8122047b5732266883708f847a7bd23c0ed2fe7bf8e19e834e045
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -63,7 +63,7 @@ For instructions on upgrading to newer versions, visit
63
63
 
64
64
  * Mongoid now uses the official Mongo Ruby Driver 2.x instead of Moped.
65
65
 
66
- * Most driver specific configuration options have changed, please see [here](http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.
66
+ * Most driver specific configuration options have changed, please see [here](https://www.mongodb.com/docs/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.
67
67
 
68
68
  * All references to `session` are now replaced with `client`. This includes the mongoid.yml configuration, `store_in` options, and all exceptions and modules with `Session` in the name.
69
69
 
@@ -872,8 +872,8 @@ child elements.
872
872
  handling of validations. (Gerad Suyderhoud)
873
873
 
874
874
  * \#2443 `expire_after_seconds` is now a valid index option
875
- (http://docs.mongodb.org/manual/core/indexes/#ttl-indexes,
876
- http://docs.mongodb.org/manual/tutorial/expire-data/).
875
+ (https://www.mongodb.com/docs/manual/core/indexes/#ttl-indexes,
876
+ https://www.mongodb.com/docs/manual/tutorial/expire-data/).
877
877
 
878
878
  class Event
879
879
  include Mongoid::Document
data/README.md CHANGED
@@ -8,11 +8,11 @@ Mongoid is an ODM (Object-Document Mapper) framework for MongoDB in Ruby.
8
8
  Documentation
9
9
  -------------
10
10
 
11
- Mongoid has [extensive user documentation](https://docs.mongodb.com/mongoid/current/).
12
- [API documentation](https://docs.mongodb.com/mongoid/current/api/) is also available.
11
+ Mongoid has [extensive user documentation](https://www.mongodb.com/docs/mongoid/current/).
12
+ [API documentation](https://www.mongodb.com/docs/mongoid/current/api/) is also available.
13
13
 
14
14
  Mongoid is built on top of the MongoDB Ruby driver which has
15
- [its own user documentation](https://docs.mongodb.com/ruby-driver/current/).
15
+ [its own user documentation](https://www.mongodb.com/docs/ruby-driver/current/).
16
16
 
17
17
  Compatibility
18
18
  -------------
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler"
4
+ require "bundler/gem_tasks"
4
5
  Bundler.setup
5
6
 
6
7
  ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
@@ -9,53 +10,25 @@ $: << File.join(ROOT, 'spec/shared/lib')
9
10
 
10
11
  require "rake"
11
12
  require "rspec/core/rake_task"
13
+ require 'mrss/spec_organizer'
12
14
 
13
- if File.exist?('./spec/shared/lib/tasks/candidate.rake')
14
- load 'spec/shared/lib/tasks/candidate.rake'
15
- end
15
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
16
+ require "mongoid/version"
17
+
18
+ tasks = Rake.application.instance_variable_get('@tasks')
19
+ tasks['release:do'] = tasks.delete('release')
16
20
 
17
- desc 'Build the gem'
21
+ task :gem => :build
18
22
  task :build do
19
- command = %w[ gem build ]
20
- command << "--output=#{ENV['GEM_FILE_NAME']}" if ENV['GEM_FILE_NAME']
21
- command << (ENV['GEMSPEC'] || 'mongoid.gemspec')
22
- system(*command)
23
+ system "gem build mongoid.gemspec"
23
24
  end
24
25
 
25
- # `rake version` is used by the deployment system so get the release version
26
- # of the product beng deployed. It must do nothing more than just print the
27
- # product version number.
28
- #
29
- # See the mongodb-labs/driver-github-tools/ruby/publish Github action.
30
- desc "Print the current value of Mongoid::VERSION"
31
- task :version do
32
- require 'mongoid/version'
33
-
34
- puts Mongoid::VERSION
26
+ task :install => :build do
27
+ system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
35
28
  end
36
29
 
37
- # overrides the default Bundler-provided `release` task, which also
38
- # builds the gem. Our release process assumes the gem has already
39
- # been built (and signed via GPG), so we just need `rake release` to
40
- # push the gem to rubygems.
41
30
  task :release do
42
- require 'mongoid/version'
43
-
44
- if ENV['GITHUB_ACTION'].nil?
45
- abort <<~WARNING
46
- `rake release` must be invoked from the `Mongoid Release` GitHub action,
47
- and must not be invoked locally. This ensures the gem is properly signed
48
- and distributed by the appropriate user.
49
-
50
- Note that it is the `rubygems/release-gem@v1` step in the `Mongoid Release`
51
- action that invokes this task. Do not rename or remove this task, or the
52
- release-gem step will fail. Reimplement this task with caution.
53
-
54
- mongoid-#{Mongoid::VERSION}.gem was NOT pushed to RubyGems.
55
- WARNING
56
- end
57
-
58
- system 'gem', 'push', "mongoid-#{Mongoid::VERSION}.gem"
31
+ raise "Please use ./release.sh to release"
59
32
  end
60
33
 
61
34
  RSpec::Core::RakeTask.new("spec") do |spec|
@@ -82,8 +55,6 @@ RUN_PRIORITY = %i(
82
55
  )
83
56
 
84
57
  def spec_organizer
85
- require 'mrss/spec_organizer'
86
-
87
58
  Mrss::SpecOrganizer.new(
88
59
  root: ROOT,
89
60
  classifiers: CLASSIFIERS,
@@ -119,36 +90,16 @@ task :docs => 'docs:yard'
119
90
  namespace :docs do
120
91
  desc "Generate yard documention"
121
92
  task :yard do
122
- require "mongoid/version"
123
-
124
93
  out = File.join('yard-docs', Mongoid::VERSION)
125
94
  FileUtils.rm_rf(out)
126
95
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
127
96
  end
128
97
  end
129
98
 
130
- desc 'Build and validate the evergreen config'
131
- task eg: %w[ eg:build eg:validate ]
132
-
133
- # 'eg' == 'evergreen', but evergreen is too many letters for convenience
134
- namespace :eg do
135
- desc 'Builds the .evergreen/config.yml file from the templates'
136
- task :build do
137
- ruby '.evergreen/update-evergreen-configs'
138
- end
139
-
140
- desc 'Validates the .evergreen/config.yml file'
141
- task :validate do
142
- system 'evergreen validate --project mongoid .evergreen/config.yml'
143
- end
144
-
145
- desc 'Updates the evergreen executable to the latest available version'
146
- task :update do
147
- system 'evergreen get-update --install'
148
- end
149
-
150
- desc 'Runs the current branch as an evergreen patch'
151
- task :patch do
152
- system 'evergreen patch --uncommitted --project mongoid --browse --auto-description --yes'
99
+ namespace :release do
100
+ task :check_private_key do
101
+ unless File.exist?('gem-private_key.pem')
102
+ raise "No private key present, cannot release"
103
+ end
153
104
  end
154
105
  end
@@ -31,6 +31,17 @@ en:
31
31
  since the document did not actually get saved."
32
32
  resolution: "Double check all before callbacks to make sure they are
33
33
  not unintentionally returning false."
34
+ create_collection_failure:
35
+ message: "Cannot create collection %{collection_name}
36
+ with options %{collection_options}. The following error was raised:
37
+ %{error}."
38
+ summary: "The server rejected createCollection command with given collection
39
+ options. This may happen when some of the options are invalid, or not
40
+ supported by your version of the server."
41
+ resolution: "Double check that collection options for the collection
42
+ %{collection_name} are valid. Consult with Ruby driver documentation
43
+ and MongoDB documentation if the desired options are supported by
44
+ your version of the server."
34
45
  criteria_argument_required:
35
46
  message: "Calling Criteria methods with nil arguments is not allowed."
36
47
  summary: "Arguments to Criteria methods cannot be nil, and most
@@ -86,11 +97,24 @@ en:
86
97
  resolution: "Search for an id/shard key that is in the database or set
87
98
  the Mongoid.raise_not_found_error configuration option to false,
88
99
  which will cause nil to be returned instead of raising this error."
100
+ drop_collection_failure:
101
+ message: "Cannot drop collection %{collection_name}."
102
+ summary: "Mongoid tried to drop collection %{collection_name}, but the
103
+ collection still exists in the database."
104
+ resolution: "Try to drop the collection manually using Ruby driver or
105
+ mongo shell."
89
106
  empty_config_file:
90
107
  message: "Empty configuration file: %{path}."
91
108
  summary: "Your mongoid.yml configuration file appears to be empty."
92
109
  resolution: "Ensure your configuration file contains the correct contents.
93
- Refer to: https://docs.mongodb.com/mongoid/current/reference/configuration/"
110
+ Refer to: https://www.mongodb.com/docs/mongoid/current/reference/configuration/"
111
+ immutable_attribute:
112
+ message: "Attempted to change the immutable attribute '%{name}' with
113
+ the value: %{value}."
114
+ summary: "Immutable attributes can only have values set when the
115
+ document is a new record."
116
+ resolution: "Do not attempt to update the value of '%{name}' after
117
+ the document is persisted."
94
118
  invalid_collection:
95
119
  message: "Access to the collection for %{klass} is not allowed."
96
120
  summary: "%{klass}.collection was called, and %{klass} is an embedded
@@ -105,38 +129,20 @@ en:
105
129
  A collation option is only supported if the query is executed on a MongoDB server
106
130
  with version >= 3.4."
107
131
  resolution: "Remove the collation option from the query."
108
- in_memory_regexp_timeout:
109
- message: "Evaluating this query in memory exceeded the %{limit} second
110
- limit that applies to conditions containing a regular expression."
111
- summary: "Mongoid evaluates some conditions in the calling thread
112
- rather than sending them to the server: queries against an embedded
113
- association, removing documents from an association by condition,
114
- and Document#_matches?. A regular expression in such a condition
115
- runs locally. Mongoid limits the total time one in-memory
116
- evaluation may spend matching, because both the cost of a single
117
- match and the number of matches performed grow with the condition,
118
- and a pattern built from end-user input can be made to consume an
119
- unbounded amount of CPU. The limit is cumulative over the whole
120
- evaluation rather than per match. Where the Ruby in use offers no
121
- per-Regexp timeout the limit is enforced as wall clock over the
122
- whole in-memory evaluation, so there it can be exceeded by a large
123
- scan even when the pattern itself is cheap."
124
- resolution: "Check whether the pattern in this query comes from user
125
- input; if it does, validate it before querying. If the query is
126
- legitimate and simply large, raise
127
- Mongoid::Config.in_memory_regexp_time_limit, or set it to nil to
128
- remove the limit entirely. The limit in force is the smaller of
129
- that setting and any global Regexp.timeout the application has set,
130
- so check both. On JRuby, and on MRI before 3.2, there is no
131
- per-Regexp timeout, so what the limit bounds there is the elapsed
132
- time of the whole in-memory evaluation rather than the time spent
133
- matching."
132
+ invalid_async_query_executor:
133
+ message: "Invalid async_query_executor option: %{executor}."
134
+ summary: "A invalid async query executor was specified.
135
+ The valid options are: %{options}."
136
+ resolution: "Pick an allowed option or fix the typo. If you were
137
+ expecting the option to be there, please consult the following page
138
+ with respect to Mongoid's configuration:\n\n
139
+ \_\_https://www.mongodb.com/docs/mongoid/current/reference/configuration/#mongoid-configuration-options"
134
140
  invalid_config_file:
135
141
  message: "Invalid configuration file: %{path}."
136
142
  summary: "Your mongoid.yml configuration file does not contain the
137
143
  correct file structure."
138
144
  resolution: "Ensure your configuration file contains the correct contents.
139
- Refer to: https://docs.mongodb.com/mongoid/current/reference/configuration/"
145
+ Refer to: https://www.mongodb.com/docs/mongoid/current/reference/configuration/"
140
146
  invalid_config_option:
141
147
  message: "Invalid configuration option: %{name}."
142
148
  summary: "A invalid configuration option was provided in your
@@ -223,14 +229,21 @@ en:
223
229
  \_\_\_\_field :%{name}, %{option}: true\n
224
230
  \_\_end\n\n
225
231
  Refer to:
226
- https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-options"
232
+ https://www.mongodb.com/docs/mongoid/current/reference/fields/#custom-field-options"
227
233
  invalid_field_type:
228
234
  message: "Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'."
229
235
  summary: "Model '%{klass}' defines a field '%{field}' with an unknown type value
230
236
  %{type_inspection}."
231
237
  resolution: "Please provide a valid type value for the field.
232
238
  Refer to:
233
- https://docs.mongodb.com/mongoid/current/reference/fields/#using-symbols-or-strings-instead-of-classes"
239
+ https://www.mongodb.com/docs/mongoid/current/reference/fields/#using-symbols-or-strings-instead-of-classes"
240
+ invalid_global_executor_concurrency:
241
+ message: "Invalid global_executor_concurrency option."
242
+ summary: "You set global_executor_concurrency while async_query_executor
243
+ option is not set to :global_thread_pool. The global_executor_concurrency is
244
+ allowed only for the global thread pool executor."
245
+ resolution: "Set global_executor_concurrency option to :global_thread_pool
246
+ or remove global_executor_concurrency option."
234
247
  invalid_includes:
235
248
  message: "Invalid includes directive: %{klass}.includes(%{args})"
236
249
  summary: "Eager loading in Mongoid only supports providing arguments
@@ -341,7 +354,7 @@ en:
341
354
  invalid_storage_options:
342
355
  message: "Invalid options passed to %{klass}.store_in: %{options}."
343
356
  summary: "The :store_in macro takes only a hash of parameters with
344
- the keys :database, :collection, or :client."
357
+ the keys :database, :collection, :collection_options, or :client."
345
358
  resolution: "Change the options passed to store_in to match the
346
359
  documented API, and ensure all keys in the options hash are
347
360
  symbols.\n\n
@@ -350,12 +363,6 @@ en:
350
363
  \_\_\_\_include Mongoid::Document\n
351
364
  \_\_\_\_store_in collection: 'artists', database: 'music'\n
352
365
  \_\_end\n\n"
353
- invalid_storage_parent:
354
- message: "Invalid store_in call on class %{klass}."
355
- summary: "The :store_in macro can only be called on a base Mongoid Document"
356
- resolution: "Remove the store_in call on class %{klass}, as it will use its
357
- parent store configuration. Or remove the hierarchy extension for this
358
- class."
359
366
  invalid_time:
360
367
  message: "'%{value}' is not a valid Time."
361
368
  summary: "Mongoid tries to serialize the values for Date, DateTime, and
@@ -571,9 +578,8 @@ en:
571
578
  resolution: "Don't define '%{name}' as readonly, or do not attempt
572
579
  to update its value after the document is persisted."
573
580
  readonly_document:
574
- message: "Attempted to persist the readonly document '%{klass}'."
575
- summary: "Documents loaded from the database using #only
576
- cannot be persisted."
581
+ message: "Attempted to persist a readonly document of class '%{klass}'."
582
+ summary: "Documents that are marked readonly cannot be persisted."
577
583
  resolution: "Don't attempt to persist documents that are flagged as
578
584
  readonly."
579
585
  scope_overwrite:
@@ -115,11 +115,7 @@ module Mongoid
115
115
  # during binding or when cascading callbacks. Whenever we retrieve
116
116
  # associations within the codebase, we use without_autobuild.
117
117
  if !without_autobuild? && association.embedded? && attribute_missing?(field_name)
118
- # We always allow accessing the parent document of an embedded one.
119
- try_get_parent = association.is_a?(
120
- Mongoid::Association::Embedded::EmbeddedIn
121
- ) && field_name == association.key
122
- raise ActiveModel::MissingAttributeError, "Missing attribute: '#{field_name}'" unless try_get_parent
118
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{field_name}'"
123
119
  end
124
120
 
125
121
  if !reload && (value = ivar(name)) != false
@@ -210,7 +206,7 @@ module Mongoid
210
206
 
211
207
  # Positional projection is specified as "foo.$". In this case the
212
208
  # document that the $ is referring to should be retrieved with all
213
- # fields. See https://docs.mongodb.com/manual/reference/operator/projection/positional/
209
+ # fields. See https://www.mongodb.com/docs/manual/reference/operator/projection/positional/
214
210
  # and https://jira.mongodb.org/browse/MONGOID-4769.
215
211
  if filtered.keys == %w($)
216
212
  filtered = nil
@@ -255,7 +251,7 @@ module Mongoid
255
251
  # @example Parse the args.
256
252
  # doc.parse_args(:name => "Joe")
257
253
  #
258
- # @param [ Array ] args The arguments.
254
+ # @param [ Hash... ] *args The arguments.
259
255
  #
260
256
  # @return [ Array<Hash> ] The attributes and options.
261
257
  def parse_args(*args)
@@ -27,7 +27,7 @@ module Mongoid
27
27
  # @example Parse the args.
28
28
  # doc.parse_args(:name => "Joe")
29
29
  #
30
- # @param [ Array ] args The arguments.
30
+ # @param [ Hash... ] *args The arguments.
31
31
  #
32
32
  # @return [ Array<Hash> ] The attributes and options.
33
33
  def parse_args(*args)
@@ -11,15 +11,11 @@ module Mongoid
11
11
  included do
12
12
  class_attribute :dependents
13
13
 
14
- # Note the leading underscore: without it, ActiveSupport's
15
- # class_attribute would generate a helper method for this attribute
16
- # that collides with one it generates for :dependents.
17
- #
18
14
  # @api private
19
- class_attribute :_dependents_owner
15
+ class_attribute :dependents_owner
20
16
 
21
17
  self.dependents = []
22
- self._dependents_owner = self
18
+ self.dependents_owner = self
23
19
  end
24
20
 
25
21
  class_methods do
@@ -54,9 +50,9 @@ module Mongoid
54
50
  def self.define_dependency!(association)
55
51
  validate!(association)
56
52
  association.inverse_class.tap do |klass|
57
- if klass._dependents_owner != klass
53
+ if klass.dependents_owner != klass
58
54
  klass.dependents = []
59
- klass._dependents_owner = klass
55
+ klass.dependents_owner = klass
60
56
  end
61
57
 
62
58
  if association.dependent && !klass.dependents.include?(association)
@@ -31,9 +31,6 @@ module Mongoid
31
31
  docs_map = {}
32
32
  queue = [ klass.to_s ]
33
33
 
34
- # account for single-collection inheritance
35
- queue.push(klass.root_class.to_s) if klass != klass.root_class
36
-
37
34
  while klass = queue.shift
38
35
  if as = assoc_map.delete(klass)
39
36
  as.each do |assoc|
@@ -97,7 +97,7 @@ module Mongoid
97
97
  # @example Batch replace the documents.
98
98
  # batchable.batch_replace([ doc_one, doc_two ])
99
99
  #
100
- # @param [ Array<Document> ] docs The docs to replace with.
100
+ # @param [ Array<Document> | Array<Hash> ] docs The docs to replace with.
101
101
  #
102
102
  # @return [ Array<Hash> ] The inserts.
103
103
  def batch_replace(docs)
@@ -235,7 +235,7 @@ module Mongoid
235
235
  # @example Normalize the docs.
236
236
  # batchable.normalize_docs(docs)
237
237
  #
238
- # @param [ Array<Hash | Document> ] docs The docs to normalize.
238
+ # @param [ Array<Document> | Array<Hash> ] docs The docs to normalize.
239
239
  #
240
240
  # @return [ Array<Document> ] The docs.
241
241
  def normalize_docs(docs)
@@ -15,8 +15,8 @@ module Mongoid
15
15
  # @example Build the document.
16
16
  # Builder.new(meta, attrs).build
17
17
  #
18
- # @param [ Object ] base The object.
19
- # @param [ Object ] object The parent hash or document.
18
+ # @param [ Document ] base The object.
19
+ # @param [ Document | Hash ] object The parent hash or document.
20
20
  # @param [ String ] type Not used in this context.
21
21
  # @param [ Hash ] selected_fields Fields which were retrieved via
22
22
  # #only. If selected_fields are specified, fields not listed in it
@@ -30,7 +30,7 @@ module Mongoid
30
30
  # @example Substitute the new document.
31
31
  # person.name.substitute(new_name)
32
32
  #
33
- # @param [ Document ] replacement A document to replace the target.
33
+ # @param [ Document | Hash ] replacement A document to replace the target.
34
34
  #
35
35
  # @return [ Document | nil ] The association or nil.
36
36
  def substitute(replacement)
@@ -40,6 +40,7 @@ module Mongoid
40
40
  return nil
41
41
  end
42
42
  _base.new_record = true
43
+ replacement = Factory.build(klass, replacement) if replacement.is_a?(::Hash)
43
44
  self._target = replacement
44
45
  bind_one
45
46
  self
@@ -17,8 +17,9 @@ module Mongoid
17
17
  # @example Build the documents.
18
18
  # Builder.new(meta, attrs).build
19
19
  #
20
- # @param [ Object ] base The base object.
21
- # @param [ Object ] object The object to use to build the association.
20
+ # @param [ Document ] base The base object.
21
+ # @param [ Array<Document> | Array<Hash> ] object The object to use
22
+ # to build the association.
22
23
  # @param [ String ] type Not used in this context.
23
24
  # @param [ Hash ] selected_fields Fields which were retrieved via
24
25
  # #only. If selected_fields are specified, fields not listed in it
@@ -19,7 +19,7 @@ module Mongoid
19
19
  # @example Push a document.
20
20
  # person.addresses.push(address)
21
21
  #
22
- # @param [ Document | Array<Document> ] args Any number of documents.
22
+ # @param [ Document... ] *args Any number of documents.
23
23
  def <<(*args)
24
24
  docs = args.flatten
25
25
  return concat(docs) if docs.size > 1
@@ -117,7 +117,7 @@ module Mongoid
117
117
  # @example Use #persisted? inside block to count persisted documents.
118
118
  # person.addresses.count { |a| a.persisted? && a.country == "FR" }
119
119
  #
120
- # @param [ Object | Array<Object> ] args Args to delegate to the target.
120
+ # @param [ Object... ] *args Args to delegate to the target.
121
121
  #
122
122
  # @return [ Integer ] The total number of persisted embedded docs, as
123
123
  # flagged by the #persisted? method.
@@ -252,7 +252,7 @@ module Mongoid
252
252
  # @example Finds the first matching document using a block.
253
253
  # person.addresses.find { |addr| addr.state == 'CA' }
254
254
  #
255
- # @param [ Array<Object> ] args Various arguments.
255
+ # @param [ Object... ] *args Various arguments.
256
256
  # @param [ Proc ] block Optional block to pass.
257
257
  #
258
258
  # @return [ Document | Array<Document> | nil ] A document or matching documents.
@@ -348,7 +348,7 @@ module Mongoid
348
348
  # @example Substitute the association's target.
349
349
  # person.addresses.substitute([ address ])
350
350
  #
351
- # @param [ Array<Document> ] docs The replacement docs.
351
+ # @param [ Array<Document> | Array<Hash> ] docs The replacement docs.
352
352
  #
353
353
  # @return [ Many ] The proxied association.
354
354
  def substitute(docs)
@@ -432,10 +432,10 @@ module Mongoid
432
432
  # If the method exists on the array, use the default proxy behavior.
433
433
  #
434
434
  # @param [ Symbol | String ] name The name of the method.
435
- # @param [ Array ] args The method args
435
+ # @param [ Object... ] *args The method args.
436
436
  # @param [ Proc ] block Optional block to pass.
437
437
  #
438
- # @return [ Criteria, Object ] A Criteria or return value from the target.
438
+ # @return [ Criteria | Object ] A Criteria or return value from the target.
439
439
  ruby2_keywords def method_missing(name, *args, &block)
440
440
  return super if _target.respond_to?(name)
441
441
  klass.send(:with_scope, criteria) do
@@ -17,7 +17,7 @@ module Mongoid
17
17
  # Builder.new(meta, attrs).build
18
18
  #
19
19
  # @param [ Document ] base The document this association hangs off of.
20
- # @param [ Document ] object The related document.
20
+ # @param [ Document | Hash ] object The related document.
21
21
  # @param [ String ] _type Not used in this context.
22
22
  # @param [ Hash ] selected_fields Fields which were retrieved via
23
23
  # #only. If selected_fields are specified, fields not listed in it
@@ -32,8 +32,8 @@ module Mongoid
32
32
  bind_one
33
33
  characterize_one(_target)
34
34
  update_attributes_hash(_target)
35
- _target.save if persistable?
36
35
  _base._reset_memoized_descendants!
36
+ _target.save if persistable?
37
37
  end
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ module Mongoid
43
43
  # @example Substitute the new document.
44
44
  # person.name.substitute(new_name)
45
45
  #
46
- # @param [ Document ] replacement A document to replace the target.
46
+ # @param [ Document | Hash ] replacement A document to replace the target.
47
47
  #
48
48
  # @return [ Document | nil ] The association or nil.
49
49
  def substitute(replacement)
@@ -35,15 +35,10 @@ module Mongoid
35
35
  # @api private
36
36
  class_attribute :aliased_associations
37
37
 
38
- # @return [ Set<String> ] The set of associations that are configured
39
- # with :store_as parameter.
40
- class_attribute :stored_as_associations
41
-
42
38
  self.embedded = false
43
39
  self.embedded_relations = BSON::Document.new
44
40
  self.relations = BSON::Document.new
45
41
  self.aliased_associations = {}
46
- self.stored_as_associations = Set.new
47
42
  end
48
43
 
49
44
  # This is convenience for libraries still on the old API.
@@ -224,7 +219,6 @@ module Mongoid
224
219
  self.relations = self.relations.merge(name => assoc)
225
220
  if assoc.embedded? && assoc.respond_to?(:store_as) && assoc.store_as != name
226
221
  self.aliased_associations[assoc.store_as] = name
227
- self.stored_as_associations << assoc.store_as
228
222
  end
229
223
  end
230
224
  end
@@ -169,7 +169,7 @@ module Mongoid
169
169
  # @param [ Hash ] attrs The single document attributes to process.
170
170
  def update_nested_relation(parent, id, attrs)
171
171
  first = existing.first
172
- converted = convert_id(first ? first.class : association.klass, id)
172
+ converted = first ? convert_id(first.class, id) : id
173
173
 
174
174
  if existing.where(_id: converted).exists?
175
175
  # document exists in association
@@ -179,46 +179,11 @@ module Mongoid
179
179
  else
180
180
  update_document(doc, attrs)
181
181
  end
182
- elsif association.embedded?
183
- raise Errors::DocumentNotFound.new(association.klass, id)
184
- elsif destroyable?(attrs)
185
- # A destroy of a document that is not in the association is
186
- # ignored, rather than reaching for it outside the association.
187
- nil
188
- elsif Mongoid.allow_reparenting_via_nested_attributes?
189
- Mongoid::Warnings.warn_reparenting_via_nested_attributes
190
-
182
+ else
191
183
  # push existing document to association
192
184
  doc = association.klass.unscoped.find(converted)
193
- # find returns nil instead of raising when
194
- # Mongoid.raise_not_found_error is false; a missing document
195
- # must still be an error here, consistent with the other
196
- # not-found branches.
197
- raise Errors::DocumentNotFound.new(association.klass, id) if doc.nil?
198
-
199
185
  update_document(doc, attrs)
200
- existing.push(doc)
201
- else
202
- raise Errors::DocumentNotFound.new(association.klass, not_found_params(parent, id))
203
- end
204
- end
205
-
206
- # The params to report when an id in the nested attributes could not
207
- # be resolved within the association.
208
- #
209
- # @api private
210
- #
211
- # @param [ Document ] parent The parent document.
212
- # @param [ String | BSON::ObjectId ] id of the related document.
213
- #
214
- # @return [ Hash | Object ] The params for the not found error.
215
- def not_found_params(parent, id)
216
- if association.is_a?(Association::Referenced::HasAndBelongsToMany)
217
- # A many-to-many association has no foreign key on the child, so
218
- # the id is only ever resolved within the association itself.
219
- id
220
- else
221
- { _id: id, association.foreign_key => parent.id }
186
+ existing.push(doc) unless destroyable?(attrs)
222
187
  end
223
188
  end
224
189
  end