Module: Mongoid::Config::Introspection Private
- Extended by:
- Introspection
- Included in:
- Introspection
- Defined in:
- lib/mongoid/config/introspection.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
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.
Defined Under Namespace
Classes: Option
Constant Summary collapse
- OPTION_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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
- CONFIG_RB_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The full path to the source file of the Mongoid::Config module.
File.absolute_path(File.join( File.dirname(__FILE__), "../config.rb"))
Instance Method Summary collapse
-
#options(include_deprecated: false) ⇒ Array<Introspection::Option>
private
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>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extracts the available configuration options from the Mongoid::Config source file, and returns them as an array of hashes.
142 143 144 145 146 147 148 |
# 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 |