class Mongoid::Config::Introspection::Option
A helper class to represent an individual option, its name, its default value, and the comment that documents it.
Attributes
The comment that describes this option, as scraped from mongoid/config.rb.
@return [ String ] The (possibly multi-line) comment. Each line is
prefixed with the Ruby comment character ("#").
The default value of this option.
@return [ Object
] The default value of the option, typically a
String, Symbol, nil, true, or false.
The name of this option.
@return [ String ] The name of the option
Public Class Methods
Instantiate an option from an array of Regex captures.
@param [ Array<String> ] captures The array with the Regex captures
to use to instantiate the option. The element at index 1 must be the comment, at index 2 must be the name, and at index 3 must be the default value.
@return [ Option
] The newly instantiated Option
object.
# File lib/mongoid/config/introspection.rb, line 46 def self.from_captures(captures) new(captures[2], captures[3], captures[1]) end
Create a new Option
instance with the given name, default value, and comment.
@param [ String ] name The option’s name. @param [ String ] default The option’s default value, as a String
representing the actual Ruby value.
@param [ String ] comment The multi-line comment describing the
option.
# File lib/mongoid/config/introspection.rb, line 58 def initialize(name, default, comment) @name, @default, @comment = name, default, unindent(comment) end
Public Instance Methods
Compare self with the given option.
@return [ true | false ] If name, default, and comment are all the
same, return true. Otherwise, false.
# File lib/mongoid/config/introspection.rb, line 89 def ==(option) name == option.name && default == option.default && comment == option.comment end
Reports whether or not the text “(Deprecated)” is present in the option’s comment.
@return [ true | false ] whether the option is deprecated or not.
# File lib/mongoid/config/introspection.rb, line 81 def deprecated? comment.include?("(Deprecated)") end
Indent the comment by the requested amount, optionally indenting the first line, as well.
param [ Integer ] indent The number of spaces to indent each line
(Default: 2)
param [ true | false ] indent_first_line Whether or not to indent
the first line of the comment (Default: false)
@return [ String ] the reformatted comment
# File lib/mongoid/config/introspection.rb, line 71 def indented_comment(indent: 2, indent_first_line: false) comment.gsub(/^/, " " * indent).tap do |result| result.strip! unless indent_first_line end end
Private Instance Methods
Removes any existing whitespace from the beginning of each line in the text.
@param [ String ] text The text to unindent.
@return [ String ] the unindented text.
# File lib/mongoid/config/introspection.rb, line 103 def unindent(text) text.strip.gsub(/^\s+/, "") end