lib/mongoid.rb in mongoid-8.1.7 vs lib/mongoid.rb in mongoid-9.0.0

- old
+ new

@@ -1,11 +1,11 @@ # frozen_string_literal: true +# rubocop:todo all require "forwardable" require "time" require "set" -require "ruby2_keywords" require "active_support" require "active_support/core_ext" require "active_support/json" require "active_support/inflector" @@ -19,31 +19,35 @@ require "mongoid/version" require "mongoid/deprecable" require "mongoid/config" require "mongoid/persistence_context" +require "mongoid/loadable" require "mongoid/loggable" require "mongoid/clients" require "mongoid/document" require "mongoid/tasks/database" -require "mongoid/query_cache" +require "mongoid/tasks/encryption" require "mongoid/warnings" require "mongoid/utils" -# If we are using Rails then we will include the Mongoid railtie. This has all -# the nifty initializers that Mongoid needs. +# If we are using Rails then we will include the Mongoid railtie. +# This configures initializers required to integrate Mongoid with Rails. if defined?(Rails) require "mongoid/railtie" end -# add english load path by default +# Add English locale config to load path by default. I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml") +# Top-level module for project. module Mongoid extend Forwardable extend Loggable + extend Loadable extend self + extend Clients::Sessions::ClassMethods # A string added to the platform details of Ruby driver client handshake documents. PLATFORM_DETAILS = "mongoid-#{VERSION}".freeze # The minimum MongoDB version supported. @@ -94,10 +98,20 @@ # @return [ true ] True. def disconnect_clients Clients.disconnect end + # Reconnect all active clients. + # + # @example Reconnect all active clients. + # Mongoid.reconnect_clients + # + # @return [ true ] True. + def reconnect_clients + Clients.reconnect + end + # Convenience method for getting a named client. # # @example Get a named client. # Mongoid.client(:default) # @@ -111,21 +125,40 @@ # # @example Delegate the configuration methods. # Mongoid.database = Mongo::Connection.new.db("test") def_delegators Config, *(Config.public_instance_methods(false) - [ :logger=, :logger ]) + # Define persistence context that is used when a transaction method is called + # on Mongoid module. + # + # @api private + def persistence_context + PersistenceContext.get(Mongoid) || PersistenceContext.new(Mongoid) + end + # Define client that is used when a transaction method is called + # on Mongoid module. This MUST be the default client. + # + # @api private + def storage_options + { client: :default } + end + # Module used to prepend the discriminator key assignment function to change # the value assigned to the discriminator key to a string. # # @api private module GlobalDiscriminatorKeyAssignment + # This class is used for obtaining the method definition location for # Mongoid methods. class InvalidFieldHost include Mongoid::Document end + # Sets the global discriminator key name. + # + # @param [ String | Symbol ] value The new discriminator key name. def discriminator_key=(value) Mongoid::Fields::Validators::Macro.validate_field_name(InvalidFieldHost, value) value = value.to_s super end