module Mongoid::Config::Introspection
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.
@api private
Constants
- CONFIG_RB_PATH
The full path to the source file of the
Mongoid::Config
module.- OPTION_PATTERN
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
Public Instance Methods
options(include_deprecated: false)
click to toggle source
Extracts the available configuration options from the Mongoid::Config
source file, and returns them as an array of hashes.
@param [ true | false ] include_deprecated Whether deprecated options
should be included in the list. (Default: false)
@return [ Array<Introspection::Option>> ] the array of option objects
representing each defined option, in alphabetical order by name.
# File lib/mongoid/config/introspection.rb, line 142 def options(include_deprecated: false) src = File.read(CONFIG_RB_PATH) src.scan(OPTION_PATTERN) .map { |opt| Option.from_captures(opt) } .reject { |opt| !include_deprecated && opt.deprecated? } .sort_by { |opt| opt.name } end