-
Notifications
You must be signed in to change notification settings - Fork 532
RUBY-3552 Deprecate support for server version 3.6 #2978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+156
−8
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6addbf
RUBY-3552 Deprecate support for server version 3.6
jamis 74cfcb5
Merge branch 'master' into 3552-deprecate-3.6
jamis e113971
feedback from copilot
jamis 1c87a5d
Merge remote-tracking branch 'upstream/master' into 3552-deprecate-3.6
jamis ffdfdd0
extend, not include (for Ruby 2.7)
jamis c32a07f
reverse the prefix-match logic so it actually works
jamis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'mongo/loggable' | ||
|
|
||
| module Mongo | ||
| # Used for reporting deprecated behavior in the driver. When it is possible | ||
| # to detect that a deprecated feature is being used, a warning should be issued | ||
| # through this module. | ||
| # | ||
| # The warning will be issued no more than once for that feature, regardless | ||
| # of how many times Mongo::Deprecations.warn is called. | ||
| # | ||
| # @example Issue a deprecation warning. | ||
| # Mongo::Deprecations.warn(:old_feature, "The old_feature is deprecated, use new_feature instead.") | ||
| # | ||
| # @api private | ||
| module Deprecations | ||
| extend self | ||
| extend Mongo::Loggable | ||
|
|
||
| # Mutex for synchronizing access to warned features. | ||
| # @api private | ||
| MUTEX = Thread::Mutex.new | ||
|
|
||
| # Issue a warning about a deprecated feature. The warning is written to the | ||
| # logger, and will not be written more than once per feature. | ||
| # | ||
| # @param [ String | Symbol ] feature The deprecated feature. | ||
| # @param [ String ] message The deprecation message. | ||
| def warn(feature, message) | ||
| MUTEX.synchronize do | ||
| return if _warned?(feature) | ||
|
|
||
| _warned!(feature) | ||
| log_warn("[DEPRECATION:#{feature}] #{message}") | ||
| end | ||
| end | ||
|
|
||
| # Check if a warning for a given deprecated feature has already been issued. | ||
| # | ||
| # @param [ String | Symbol ] feature The deprecated feature. | ||
| # @param [ true | false ] prefix Whether to check for prefix matches. | ||
| # | ||
| # @return [ true | false ] If a warning has already been issued. | ||
| def warned?(feature, prefix: false) | ||
| MUTEX.synchronize { _warned?(feature, prefix: prefix) } | ||
| end | ||
|
|
||
| # Mark that a warning for a given deprecated feature has been issued. | ||
| # | ||
| # @param [ String | Symbol ] feature The deprecated feature. | ||
jamis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def warned!(feature) | ||
| MUTEX.synchronize { _warned!(feature) } | ||
| nil | ||
| end | ||
|
|
||
| # Clears all memory of previously warned features. | ||
| def clear! | ||
| MUTEX.synchronize { warned_features reset: true } | ||
| nil | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Set of features that have already been warned about. | ||
| # | ||
| # @param [ true | false ] reset Whether to reset the warned features. | ||
| # | ||
| # @return [ Set<String> ] The set of warned features. | ||
| def warned_features(reset: false) | ||
| @warned_features = nil if reset | ||
| @warned_features ||= Set.new | ||
| end | ||
|
|
||
| # Check if a warning for a given deprecated feature has already been issued. | ||
| # This version is not thread-safe. | ||
| # | ||
| # @param [ String | Symbol ] feature The deprecated feature. | ||
| # @param [ true | false ] prefix Whether to check for prefix matches. | ||
| # | ||
| # @return [ true | false ] If a warning has already been issued. | ||
| def _warned?(feature, prefix: false) | ||
| if prefix | ||
| warned_features.any? { |f| f.to_s.start_with?(feature) } | ||
| else | ||
| warned_features.include?(feature.to_s) | ||
| end | ||
| end | ||
|
|
||
| # Mark that a warning for a given deprecated feature has been issued. | ||
| # This version is not thread-safe. | ||
| # | ||
| # @param [ String | Symbol ] feature The deprecated feature. | ||
| def _warned!(feature) | ||
| warned_features.add(feature.to_s) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.