Module: Mongoid::Config::Introspection Private

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Defined in: lib/mongoid/config/introspection.rb


This module provides a way to inspect not only the defined configuration settings and their defaults (which are available via ‘Mongoid::Config.settings`), but also the documentation about them. It does this by scraping the mongoid/config.rb file with a regular expression to match comments with options.

Constant Summary


    The full path to the source file of the ::Mongoid::Config module.

    # File 'lib/mongoid/config/introspection.rb', line 131
    File.dirname(__FILE__), "../config.rb"))

    A regular expression that looks for option declarations of the format:

    # one or more lines of comments,
    # followed immediately by an option
    # declaration with a default value:
    option :option_name, default: "something"

    The regex produces three captures:

    1: the (potentially multiline) comment
    2: the option's name
    3: the option's default value
    # File 'lib/mongoid/config/introspection.rb', line 120
        ((?:^\s*\#.*\n)+)  # match one or more lines of comments
        ^\s+option\s+      # followed immediately by a line declaring an option
        :(\w+),\s+         # match the option's name, followed by a comma
        default:\s+(.*?)   # match the default value for the option
        (?:,.*?)?          # skip any other configuration
      \n)                  # end with a newline

Instance Method Summary

Instance Method Details

#options(include_deprecated: false) ⇒ Array<Introspection::Option>

Extracts the available configuration options from the ::Mongoid::Config source file, and returns them as an array of hashes.


  • include_deprecated (true | false)

    Whether deprecated options should be included in the list. (Default: false)


  • (Array<Introspection::Option>)

    ] the array of option objects representing each defined option, in alphabetical order by name.

[ GitHub ]

# File 'lib/mongoid/config/introspection.rb', line 142

def options(include_deprecated: false)
  src = File.read(CONFIG_RB_PATH)
    .map { |opt| Option.from_captures(opt) }
    .reject { |opt| !include_deprecated && opt.deprecated? }
    .sort_by { |opt| opt.name }