Module: Mongoid::Config::Introspection Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Defined in: | lib/mongoid/config/introspection.rb |
Overview
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
-
CONFIG_RB_PATH =
The full path to the source file of the
::Mongoid::Config
module.File.absolute_path(File.join( File.dirname(__FILE__), "../config.rb"))
-
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
%r{ ( ((?:^\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 }x
Instance Method Summary
-
#options(include_deprecated: false) ⇒ Array<Introspection::Option>
Internal use only
Extracts the available configuration options from the
::Mongoid::Config
source file, and returns them as an array of hashes.
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.
# File 'lib/mongoid/config/introspection.rb', line 142
def (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