Module: Datadog::Tracing::Contrib::Support

Defined in:
lib/datadog/tracing/contrib/support.rb

Overview

Miscellaneous support methods to aid in the creation of integrations.

Class Method Summary collapse

Class Method Details

.fully_loaded?(base_module, constant) ⇒ Boolean

Checks if a constant is loaded in a module, handling autoloaded constants correctly.

This method is particularly useful when you need to check if a constant is fully loaded, not just defined. It handles the special case of autoloaded constants, which return non-nil for ‘defined?` even when they haven’t been loaded yet.

Parameters:

  • base_module (Module)

    the module to check for the constant

  • constant (Symbol)

    the name of the constant to check

Returns:

  • (Boolean)

    true if the constant has been loaded, false otherwise



19
20
21
22
23
24
# File 'lib/datadog/tracing/contrib/support.rb', line 19

def fully_loaded?(base_module, constant)
  # Autoload constants return `constant` for `defined?`, but that doesn't mean they are loaded...
  base_module.const_defined?(constant) &&
    # ... to check that we need to call `autoload?`. If it returns `nil`, it's loaded.
    base_module.autoload?(constant).nil?
end