From e997b0ee6decd3aba3773296b2c9ab53c4cf9e95 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 8 Jul 2026 10:38:49 -0600 Subject: [PATCH] MONGOID-5931 Remove obsolete driver-version guard and document DeprecatedOptions Audited the codebase for dead and unreachable code using RuboCop lint cops, debride, and a grep/AST caller cross-reference. The codebase is largely free of dead code; the one genuine site was an obsolete guard. - clients/factory.rb: drop the `driver_version <=> [2, 13]` guard, which is always true now that the gemspec requires mongo >= 2.18.0, and remove the now-unused driver_version helper. - config.rb: document that DeprecatedOptions::OPTIONS is intentionally empty when no options are deprecated. --- lib/mongoid/clients/factory.rb | 20 +++++++------------- lib/mongoid/config.rb | 4 ++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/mongoid/clients/factory.rb b/lib/mongoid/clients/factory.rb index 564e16eb40..acbc9c8a13 100644 --- a/lib/mongoid/clients/factory.rb +++ b/lib/mongoid/clients/factory.rb @@ -111,10 +111,6 @@ def build_auto_encryption_options(opts, database) version: VERSION }.freeze - def driver_version - Mongo::VERSION.split('.')[0...2].map(&:to_i) - end - # Prepare options for Mongo::Client based on Mongoid client configuration. # # @param [ Hash ] opts Parameters from options section of Mongoid client configuration. @@ -125,16 +121,14 @@ def options(opts) options = opts.dup options[:platform] = PLATFORM_DETAILS options[:app_name] = Mongoid::Config.app_name if Mongoid::Config.app_name - if (driver_version <=> [ 2, 13 ]) >= 0 - wrap_lib = if options[:wrapping_libraries] - [ MONGOID_WRAPPING_LIBRARY ] + options[:wrapping_libraries] - else - [ MONGOID_WRAPPING_LIBRARY ] - end.tap do |wrap| - wrap << { name: 'Rails', version: ::Rails.version } if defined?(::Rails) && ::Rails.respond_to?(:version) - end - options[:wrapping_libraries] = wrap_lib + wrap_lib = if options[:wrapping_libraries] + [ MONGOID_WRAPPING_LIBRARY ] + options[:wrapping_libraries] + else + [ MONGOID_WRAPPING_LIBRARY ] + end.tap do |wrap| + wrap << { name: 'Rails', version: ::Rails.version } if defined?(::Rails) && ::Rails.respond_to?(:version) end + options[:wrapping_libraries] = wrap_lib options.reject { |k, _v| k == :hosts }.to_hash.symbolize_keys! end end diff --git a/lib/mongoid/config.rb b/lib/mongoid/config.rb index 4df6129d90..c1b15ea240 100644 --- a/lib/mongoid/config.rb +++ b/lib/mongoid/config.rb @@ -548,6 +548,10 @@ def global_client end end + # Wraps configuration options that have been deprecated so that assigning + # them emits a deprecation warning. OPTIONS is intentionally empty when no + # options are currently deprecated; it is populated as options are retired, + # at which point this module rewrites their setters to warn. module DeprecatedOptions OPTIONS = %i[]