Skip to content

Commit 4b8d9b6

Browse files
johnnyshieldsneilshwekyp-mongocomandeo-mongoalexbevi
authored
[READY FOR REVIEW] MONGOID-5509 Merge 8.1-stable (deprecation changes) to master (#5561)
* MONGOID-5334 ensure localized demongoization works with symbol keys (#5416) * MONGOID-5334 ensure localized demongoization works with symbol keys * MONGOID-5334 add type check * MONGOID-5334 change back type check * MONGOID-5437 extract fallback enabling logic into macro (#5428) * MONGOID-5438 initial changes from Johnny's PR * MONGOID-5438 additional changes from johnny's PR * MONGOID-5437 fix tests * MONGOID-5437 fix uniqueness test * MONGOID-5334 enforce Hash type in localized demongoize (#5430) * MONGOID-5334 add type check * MONGOID-5334 change back type check * MONGOID-5334 enforce Hash type in localized demongoize * MONGOID-5456 cast castable values for integer/float/big decimal (#5431) * MONGOID-5456 cast castable values for integer/float/big decimal * MONGOID-5456 assert duration * MONGOID-4403 Support Dirty Tracking changed from/to (#5432) * MONGOID-4403 Support Dirty Tracking changed from/to * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-4403 add false example Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5456 Add documentation for responding to to_* (#5434) * MONGOID-5456 Add documentation for responding to to_* * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5461 Change custom field options example (#5438) * MONGOID-5461 Change custom field options example * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5458 Document fallbacks option on localized fields (#5439) * MONGOID-5460 Update custom field type protocol documentation (#5441) * MONGOID-5457 Document + example of non-String field types in localized fields (#5444) * MONGOID-4698 update warning when overriding criteria methods in scope (#5442) * MONGOID-4698 update warning when overriding criteria methods in scope * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5417 Fix memory leak when call 'with' (#5409) * MONGOID-4528 Add more dirty methods (#5440) Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-4698 Correct warning to point out that klass.band doesnt conflict (#5450) * MONGOID-5226 Allow setting "store_in collection" on document subclass (#5449) * MONGOID-5226 Allow setting "store_in collection" on document subclass * remove comment * MONGOID-5226 add docs and testing * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5226 answer comments Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5293 put legacy_attributes in 7.5 defaults (#5425) * MONGOID-5293 put legacy_attributes in 7.5 * switch order * MONGOID-5293 fix defaults tests * MONGOID-5438 Implement local override for i18n parameters (#5427) * MONGOID-5438 Implement local override for i18n parameters * MONGOID-5438 get rid of enfore_available_locale changes * MONGOID-5438 get rid of before alls * MONGOID-5438 fix tests caused by rspec precedence * MONGOID-5438 attempt to fix tests when fallbacks disabled * MONGOID-5438 make fallbacks default to return [self] * MONGOID-5438 reset fallbacks * MONGOID-5438 attempt to fix tests * MONGOID-5438 retry_test * MONGOID-5438 undefine fallback methods after fallback tests * MONGOID-5438 add back defaults * MONGOID-5438 use new macros * MONGOID-5438 use before and after suite * MONGOID-5438 update mrss * MONGOID-5438 remove suite checks * MONGOID-5370 Add collection options support (#5452) Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5474 add readonly! and raise on save/update (#5455) * MONGOID-5474 add readonly! and raise on save/update * MONGOID-5474 flip flag for 9.0 and add default * MONGOID-5474 fix error tests * Update spec/mongoid/config_spec.rb * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> * Update lib/mongoid/config.rb Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5474/MONGOID-5478 add docs and release notes (#5457) * MONGOID-5474 add docs and release notes * MONGOID-5474 use read-only * MONGOID-5474 add configuration docs * MOGOID-5474 switch order of flag docs * add MONGOID-5477 use case * MONGOID-5477 / MONGOID-5474 / MONGOID-5478 add user test (#5459) * MONGOID-5474 add user test * MONGOID-5474 change to read-only * MOGOID-5474 switch order of flag docs * MONGOID-5476 update 8.1 installation version (#5464) * MONGOID-5474 flip the feature flag in 8.1 (#5456) * MONGOID-5474 flip the feature flag in 8.1 * MONGOID-5474 flip flag in configuration * MONGOID-5474 update config test * MONGOID-5227 Add test and adjust docs for dotted attribute assignment in default scope (#5474) * MONGOID-5227 Add test and adjust docs for dotted attribute assignment in default scope * MONGOID-5227 adjust docs * MONGOID-5227 clarify the docs and add tests * Update docs/reference/queries.txt Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5493: Update Gem::Specification team info (#5476) * MONGOID-5312 Document attributes method in reference (#5477) * MONGOID-5312 Document attributes method in reference * Apply suggestions from code review Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5312 update languagw Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5082 Create contributing guidelines (#5472) * MONGOID-5082 Create contributing guidelines * MONGOID-5082 propose test coverage * MONGOID-5082 whitespace * MONGOID-5082 update language * add intro * MONGOID-5445 Add load_async to criteria (#5454) Co-authored-by: Neil Shweky <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> * MONGOID-5291 Clarify whether :touch option is applicable for all updates (#5481) * MONGOID-5261 Use config_override when a test requires a certain configuration option value (#5479) * MONGOID-5261 Use config_override when a test requires a certain configuration option value * fix syntax error * MONGOID-5261 a little more cleanup * MONGOID-5261 more cleanup * more clean up * MONGOID-5261 add persistence context override * MONGOID-5261 add comment * MONGOID-5100 allow selector arguments for .exists? (#5466) * MONGOID-5100 allow selector arguments for .exists? * MONGOID-5100 add examples to the docstrings * MONGOID-5100 add docs and release notes * Empty-Commit * MONGOID-5100 allow false to be passed * MONGOID-5100 update docs and docstrings * MONGOID-5100 remove false as a param * MONGOID-5100 put back nil/false * MONGOID-5100 fix memory tests and fix limit == 0 * MONGOID-5262 Implement local time zone override for tests (#5480) * MONGOID-5506 Update 8.x docs to document unscoped behavior changing in 9.0 (#5483) * MONGOID-5506 Update 8.x docs to document unscoped behavior changing in 9.0 * Update lib/mongoid/scopable.rb * RUBY-2942: Update documentation links (#5482) * MONGOID-5363 Change #upsert to perform updating upsert rather than replacing upsert (#5492) * MONGOID-5363 add :replace option to upsert method * MONGOID-5363 add docs, release notes for 8.1/9.0 * MONGOID-5363 switch default in 8.1 (#5493) * MONGOID-5363 update docstrings, flag default, and tests for 8.1 * specify default in mongoid 9 * MONGOID-5331 Document hash assignment to associations (#5494) * MONGOID-5331 change buildable docs * MONGOID-5331 add proxy tests and fix embedded_in proxy * MONGOID-5331 update models * Update spec/mongoid/association/embedded/embedded_in/proxy_spec.rb * MONGOID-5331 update doc strings in batchable * MONGOID-5331 add docs * MONGOID-5331 add docs/release notes * Apply suggestions from code review * Update spec/mongoid/association/embedded/embedded_in/proxy_spec.rb * RUBY-3097 add/use monotonic time for deadlines (#5491) * RUBY-3097 add/use monotonic time for deadlines * remove license and fix tests * MONGOID-3834 Document association availability in custom getters and setters (#5503) * MONGOID-3834 Document association availability in custom getters and setters * add callbacks note * MONGOID-5496: Update Getting Started (Rails) tutorial for Rails 7 (#5509) * Clone Rails Tutorial and create variation for Rails 7 * Update Existing Application docs for Rails 7 * MONGOID-5532: Fix path to comments partial (#5511) * MONGOID-5533: Unnecessary edits to Comment model in Rails Getting Started (#5512) * Add note about workaround for MONGOID-4885 in Rails 6 docs * Fix whitespace * MONGOID-5521 migrate Mongoid docs to snooty (#5513) * fix code blocks * MONGOID-5521 fix all parse errors * build docs with github action * Revert "build docs with github action" This reverts commit 9ffda44. * MONGOID-5496: Update Rails 7 Tutorial (#5515) * Remove `--skip-bundle` from _Optionally Skip Tests_ section * MONGOID-5518: Add Puma dependency to Sinatra tutorial (#5516) * MONGOID-5453 Add .none_of query method (#5524) * "none_of" query method * update docs and release notes * fix underline for header * MONGOID-5539: Fix example in aggregation reference documentation (#5536) * Update aggregation.txt * Update aggregation.txt * MONGOID-5228 disallow _id to be updated on persisted documents (ported to 8.1-stable) (#5545) * port #5542 to 8.1-stable * test tweak * update 8.1 release notes to mention immutable_ids * MONGOID-5490: Deprecate :use_activesupport_time_zone (#5488) * Deprecate the use_activesupport_time_zone_deprecated config option. * Typo * Update config.rb * Update mongoid-8.1.txt --------- Co-authored-by: shields <[email protected]> * MONGOID-5509: Deprecate all feature flags which were introduced in Mongoid 7.x (#5489) * Deprecate the use_activesupport_time_zone_deprecated config option. * Typo * Mongoid 8.1 should deprecate all feature flags which were introduced in the 7.x series, with intent to remove them in Mongoid 9.0. --------- Co-authored-by: shields <[email protected]> * Remove :use_activesupport_time_zone option + improve readme around timezone usage given the change * Remove deprecated :broken_aggregables config option * Remove deprecated :broken_alias_handling config option * Remove deprecated :broken_and config option * Remove deprecated :broken_scoping config option * Remove deprecated :broken_updates config option * Remove deprecated :compare_time_by_ms config option * Remove deprecated :legacy_attributes config option * Remove deprecated :legacy_pluck_distinct config option * Remove deprecated :legacy_triple_equals config option * Remove deprecated :object_id_as_json_oid config option * Remove deprecated :overwrite_chained_operators config option * Drop support for config.load_defaults versions "7.3", "7.4", "7.5", as their options are no longer available. * Fix broken spec in Mongoid 8.1 --------- Co-authored-by: Neil Shweky <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Dmitry Rybakov <[email protected]> Co-authored-by: Alex Bevilacqua <[email protected]> Co-authored-by: Jamis Buck <[email protected]> Co-authored-by: Jamis Buck <[email protected]> Co-authored-by: shields <[email protected]>
1 parent 9892a68 commit 4b8d9b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1114
-3253
lines changed

docs/reference/configuration.txt

Lines changed: 87 additions & 203 deletions
Large diffs are not rendered by default.

docs/reference/crud.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,8 @@ operations with examples.
3939

4040
* - ``Model#attributes``
4141

42-
*Returns a hash of the document's attributes with its values in
43-
mongoized form (i.e. the way they are stored in the db).*
44-
45-
*In Mongoid 8.0 by default, and Mongoid 7.5 with the*
46-
``legacy_attributes`` *flag set to false, the object returned from this
47-
method will have class* ``Hash``, *and have string keys. In Mongoid 7.5
48-
by default, and in Mongoid 8.0 with the* ``legacy_attributes`` *flag set
49-
to true, the object returned from this method will be a*
50-
``BSON::Document`` *(and thus, indifferently accessible) if the document
51-
has been retrieved from the database, and a* ``Hash`` *with string keys
52-
if it is a new document.*
42+
*Returns the document's attributes as a ``Hash`` with string keys, and
43+
its values in Mongoized form (i.e. the way they are stored in the db).*
5344

5445
*The attributes hash also contains the attributes of all embedded
5546
documents, as well as their embedded documents, etc. If an embedded

docs/reference/fields.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ returned is defined by the :ref:`configured time zone settings <time-zones>`.
355355
field :opened_at, type: DateTime
356356
end
357357

358-
Mongoid.use_activesupport_time_zone = true
359358
Time.zone = 'Berlin'
360359

361360
ticket = Ticket.create!(opened_at: '2018-02-18 07:00:08 -0500')

docs/release-notes/mongoid-8.1.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ For all of the new methods there are also shorter forms created dynamically, e.g
9292
and ``will_save_change_to_attribute?(:name)`` is equivalent to ``will_save_change_to_name?``.
9393

9494

95+
Deprecated ``use_activesupport_time_zone`` config option
96+
--------------------------------------------------------
97+
98+
The config option ``use_activesupport_time_zone`` has been deprecated.
99+
Beginning in Mongoid 9.0, it will be ignored and always behave as true.
100+
Since ``use_activesupport_time_zone`` currently defaults to true, it is
101+
safe to remove from your config file at this time.
102+
103+
95104
Configuration DSL No Longer Requires an Argument to its Block
96105
-------------------------------------------------------------
97106

@@ -378,7 +387,7 @@ Added ``none_of`` Query Method
378387
------------------------------
379388

380389
With the addition of ``none_of``, Mongoid 8.1 allows queries to exclude
381-
conditions in bulk. The emitted query will encapsulate the specified
390+
conditions in bulk. The emitted query will encapsulate the specified
382391
criteria in a ``$nor`` operation. For example:
383392

384393
.. code:: ruby
@@ -398,3 +407,23 @@ criteria in a ``$nor`` operation. For example:
398407

399408
This would query all buildings in Portland, excluding apartments, buildings less than
400409
100 units tall, and buildings with an occupancy greater than 2500 people.
410+
411+
412+
Added ``Mongoid::Config.immutable_ids``
413+
---------------------------------------
414+
415+
Coming in Mongoid 9.0, the ``_id`` field will be immutable in both top-level
416+
and embedded documents. This addresses some inconsistency in how mutations
417+
to the ``_id`` field are treated currently. To prepare for this potentially
418+
breaking change, the ``Mongoid::Config.immutable_ids`` flag has been added. It
419+
defaults to ``false``, preserving the existing behavior, but you may set it to
420+
``true`` to prepare your apps for Mongoid 9.0. When this is set to ``true``,
421+
attempts to mutate the ``_id`` of a document will raise an exception.
422+
423+
.. code:: ruby
424+
425+
# The default in Mongoid 8.1
426+
Mongoid::Config.immutable_ids = false
427+
428+
# The default in Mongoid 9.0
429+
Mongoid::Config.immutable_ids = true

docs/release-notes/mongoid-9.0.txt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@ The complete list of releases is available `on GitHub
1717
please consult GitHub releases for detailed release notes and JIRA for
1818
the complete list of issues fixed in each release, including bug fixes.
1919

20+
Deprecated options removed
21+
--------------------------
22+
23+
**Breaking change:** The following config options are removed in Mongoid 9.0.
24+
Please ensure you have removed all references to these from your app.
25+
If you were using ``config.load_defaults 8.1`` prior to upgrading, you will not
26+
experience any behavior change. Refer to earlier release notes for the meaning
27+
of each option.
28+
29+
- ``:use_activesupport_time_zone``
30+
- ``:broken_aggregables``
31+
- ``:broken_alias_handling``
32+
- ``:broken_and``
33+
- ``:broken_scoping``
34+
- ``:broken_updates``
35+
- ``:compare_time_by_ms``
36+
- ``:legacy_attributes``
37+
- ``:legacy_pluck_distinct``
38+
- ``:legacy_triple_equals``
39+
- ``:object_id_as_json_oid``
40+
- ``:overwrite_chained_operators``
41+
42+
In addition, support for ``config.load_defaults`` versions 7.5 and
43+
prior has been dropped (you must use a minimum of version 8.0.)
44+
45+
2046
``touch`` method now clears changed state
2147
-----------------------------------------
2248

@@ -128,13 +154,10 @@ Use configured time zone to typecast Date to Time in queries
128154
-------------------------------------------------------------
129155

130156
When querying for a Time field using a Date value, Mongoid now correctly
131-
considers the ``Mongoid.use_activesupport_time_zone`` configuration option
132-
to perform type conversion.
157+
considers ``Time.zone`` to perform type conversion.
133158

134159
.. code-block:: ruby
135160

136-
Mongoid.use_activesupport_time_zone = true
137-
138161
class Magazine
139162
include Mongoid::Document
140163

@@ -147,14 +170,12 @@ to perform type conversion.
147170
#=> will return all results on or after Sept 26th, 2022
148171
# at 0:00 in Asia/Tokyo time zone.
149172

150-
In prior Mongoid versions, the above code would ignore the
151-
``Mongoid.use_activesupport_time_zone`` setting and behave as if
152-
it were false, i.e. always using the system time zone to perform
153-
the type conversion.
173+
In prior Mongoid versions, the above code would ignore the ``Time.zone``
174+
(irrespective of the now-removed ``:use_activesupport_time_zone``
175+
setting) and always using the system time zone to perform the type conversion.
154176

155177
Note that in prior Mongoid versions, typecasting Date to Time during
156-
persistence operations was already correctly using the
157-
``Mongoid.use_activesupport_time_zone`` setting.
178+
persistence operations was already correctly using time zone.
158179

159180

160181
```#touch`` method on embedded documents correctly handles ``touch: false`` option

docs/tutorials/getting-started-rails7.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Setup Mongoid
9595

9696
bin/rails g mongoid:config
9797

98-
This generator will create the ``config/mongoid.yml`` configuration file
98+
This generator will create the ``config/mongoid.yml`` configuration file
9999
(used to configure the connection to the MongoDB deployment) and the
100100
``config/initializers/mongoid.rb`` initializer file (which may be used for
101101
other Mongoid-related configuration). Note that as we are not using
@@ -334,7 +334,7 @@ Generate the default Mongoid configuration:
334334

335335
bin/rails g mongoid:config
336336

337-
This generator will create the ``config/mongoid.yml`` configuration file
337+
This generator will create the ``config/mongoid.yml`` configuration file
338338
(used to configure the connection to the MongoDB deployment) and the
339339
``config/initializers/mongoid.rb`` initializer file (which may be used for
340340
other Mongoid-related configuration). In general, it is recommended to use

lib/mongoid/association/embedded/batchable.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ def batch_clear(docs)
3838
positionally(selector, "$unset" => { path => true }),
3939
session: _session
4040
)
41-
unless Mongoid.broken_updates
42-
# This solves the case in which a user sets, clears and resets an
43-
# embedded document. Previously, since the embedded document was
44-
# already marked not a "new_record", it wouldn't be persisted to
45-
# the second time. This change fixes that and allows it to be persisted.
46-
docs.each { |doc| doc.new_record = true }
47-
end
41+
# This solves the case in which a user sets, clears and resets an
42+
# embedded document. Previously, since the embedded document was
43+
# already marked not a "new_record", it wouldn't be persisted to
44+
# the second time. This change fixes that and allows it to be persisted.
45+
docs.each { |doc| doc.new_record = true }
4846
post_process_batch_remove(docs, :delete)
4947
end
5048
_unscoped.clear

lib/mongoid/association/embedded/embeds_one/proxy.rb

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,28 @@ def substitute(replacement)
5555
# run the callbacks and state-changing code by passing persist: false in that case.
5656
_target.destroy(persist: !replacement) if persistable?
5757

58-
unless Mongoid.broken_updates
59-
# A little explanation on why this is needed... Say we have three assignments:
60-
#
61-
# canvas.palette = palette
62-
# canvas.palette = nil
63-
# canvas.palette = palette
64-
# Where canvas embeds_one palette.
65-
#
66-
# Previously, what was happening was, on the first assignment,
67-
# palette was considered a "new record" (new_record?=true) and
68-
# thus palette was being inserted into the database. However,
69-
# on the third assignment, we're trying to reassign the palette,
70-
# palette is no longer considered a new record, because it had
71-
# been inserted previously. This is not exactly accurate,
72-
# because the second assignment ultimately removed the palette
73-
# from the database, so it needs to be reinserted. Since the
74-
# palette's new_record is false, Mongoid ends up "updating" the
75-
# document, which doesn't reinsert it into the database.
76-
#
77-
# The change I introduce here, respecifies palette as a "new
78-
# record" when it gets removed from the database, so if it is
79-
# reassigned, it will be reinserted into the database.
80-
_target.new_record = true
81-
end
58+
# A little explanation on why this is needed... Say we have three assignments:
59+
#
60+
# canvas.palette = palette
61+
# canvas.palette = nil
62+
# canvas.palette = palette
63+
# Where canvas embeds_one palette.
64+
#
65+
# Previously, what was happening was, on the first assignment,
66+
# palette was considered a "new record" (new_record?=true) and
67+
# thus palette was being inserted into the database. However,
68+
# on the third assignment, we're trying to reassign the palette,
69+
# palette is no longer considered a new record, because it had
70+
# been inserted previously. This is not exactly accurate,
71+
# because the second assignment ultimately removed the palette
72+
# from the database, so it needs to be reinserted. Since the
73+
# palette's new_record is false, Mongoid ends up "updating" the
74+
# document, which doesn't reinsert it into the database.
75+
#
76+
# The change I introduce here, respecifies palette as a "new
77+
# record" when it gets removed from the database, so if it is
78+
# reassigned, it will be reinserted into the database.
79+
_target.new_record = true
8280
end
8381
unbind_one
8482
unless replacement

lib/mongoid/association/referenced/has_many/enumerable.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def ==(other)
4545
# @return [ true | false ] If the objects are equal in a case.
4646
def ===(other)
4747
return false unless other.respond_to?(:entries)
48-
if Mongoid.legacy_triple_equals
49-
other.class == Class ? (Array == other || Enumerable == other) : self == other
50-
else
51-
entries === other.entries
52-
end
48+
entries === other.entries
5349
end
5450

5551
# Append a document to the enumerable.

lib/mongoid/config.rb

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,63 +71,12 @@ module Config
7171
# existing method.
7272
option :scope_overwrite_exception, default: false
7373

74-
# Use ActiveSupport's time zone in time operations instead of the
75-
# Ruby default time zone.
76-
option :use_activesupport_time_zone, default: true
77-
7874
# Return stored times as UTC.
7975
option :use_utc, default: false
8076

8177
# Store BigDecimals as Decimal128s instead of strings in the db.
8278
option :map_big_decimal_to_decimal128, default: true
8379

84-
# Update embedded documents correctly when setting it, unsetting it
85-
# and resetting it. See MONGOID-5206 and MONGOID-5240 for more details.
86-
option :broken_updates, default: false
87-
88-
# Maintain legacy behavior of === on Mongoid documents, which returns
89-
# true in a number of cases where Ruby's === implementation would
90-
# return false.
91-
option :legacy_triple_equals, default: false
92-
93-
# When exiting a nested `with_scope' block, set the current scope to
94-
# nil instead of the parent scope for backwards compatibility.
95-
option :broken_scoping, default: false
96-
97-
# Maintain broken behavior of sum over empty result sets for backwards
98-
# compatibility.
99-
option :broken_aggregables, default: false
100-
101-
# Ignore aliased fields in embedded documents when performing pluck and
102-
# distinct operations, for backwards compatibility.
103-
option :broken_alias_handling, default: false
104-
105-
# Maintain broken `and' behavior when using the same operator on the same
106-
# field multiple times for backwards compatibility.
107-
option :broken_and, default: false
108-
109-
# Use millisecond precision when comparing Time objects with the _matches?
110-
# function.
111-
option :compare_time_by_ms, default: true
112-
113-
# Use bson-ruby's implementation of as_json for BSON::ObjectId instead of
114-
# the one monkey-patched into Mongoid.
115-
option :object_id_as_json_oid, default: false
116-
117-
# Maintain legacy behavior of pluck and distinct, which does not
118-
# demongoize the values on returning them.
119-
option :legacy_pluck_distinct, default: false
120-
121-
# Combine chained operators, which use the same field and operator,
122-
# using and's instead of overwriting them.
123-
option :overwrite_chained_operators, default: false
124-
125-
# When this flag is true, the attributes method on a document will return
126-
# a BSON::Document when that document is retrieved from the database, and
127-
# a Hash otherwise. When this flag is false, the attributes method will
128-
# always return a Hash.
129-
option :legacy_attributes, default: false
130-
13180
# Sets the async_query_executor for the application. By default the thread pool executor
13281
# is set to `:immediate. Options are:
13382
#
@@ -397,5 +346,33 @@ def global_client
397346
client
398347
end
399348
end
349+
350+
module DeprecatedOptions
351+
OPTIONS = %i[]
352+
353+
if RUBY_VERSION < '3.0'
354+
def self.prepended(klass)
355+
klass.class_eval do
356+
OPTIONS.each do |option|
357+
alias_method :"#{option}_without_deprecation=", :"#{option}="
358+
359+
define_method(:"#{option}=") do |value|
360+
Mongoid::Warnings.send(:"warn_#{option}_deprecated")
361+
send(:"#{option}_without_deprecation=", value)
362+
end
363+
end
364+
end
365+
end
366+
else
367+
OPTIONS.each do |option|
368+
define_method(:"#{option}=") do |value|
369+
Mongoid::Warnings.send(:"warn_#{option}_deprecated")
370+
super(value)
371+
end
372+
end
373+
end
374+
end
375+
376+
prepend DeprecatedOptions
400377
end
401378
end

0 commit comments

Comments
 (0)