Class: Mongoid::Config::Introspection::Option Private
- Inherits:
-
Object
- Object
- Mongoid::Config::Introspection::Option
- Defined in:
- lib/mongoid/config/introspection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A helper class to represent an individual option, its name, its default value, and the comment that documents it.
Instance Attribute Summary collapse
-
#comment ⇒ String
readonly
private
The comment that describes this option, as scraped from mongoid/config.rb.
-
#default ⇒ Object
readonly
private
The default value of this option.
-
#name ⇒ String
readonly
private
The name of this option.
Class Method Summary collapse
-
.from_captures(captures) ⇒ Option
private
Instantiate an option from an array of Regex captures.
Instance Method Summary collapse
-
#==(option) ⇒ true | false
private
Compare self with the given option.
-
#deprecated? ⇒ true | false
private
Reports whether or not the text “(Deprecated)” is present in the option’s comment.
-
#indented_comment(indent: 2, indent_first_line: false) ⇒ String
private
Indent the comment by the requested amount, optionally indenting the first line, as well.
-
#initialize(name, default, comment) ⇒ Option
constructor
private
Create a new Option instance with the given name, default value, and comment.
Constructor Details
#initialize(name, default, comment) ⇒ 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.
Create a new Option instance with the given name, default value, and comment.
58 59 60 |
# File 'lib/mongoid/config/introspection.rb', line 58 def initialize(name, default, comment) @name, @default, @comment = name, default, unindent(comment) end |
Instance Attribute Details
#comment ⇒ String (readonly)
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.
The comment that describes this option, as scraped from mongoid/config.rb.
36 37 38 |
# File 'lib/mongoid/config/introspection.rb', line 36 def comment @comment end |
#default ⇒ Object (readonly)
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.
The default value of this option.
29 30 31 |
# File 'lib/mongoid/config/introspection.rb', line 29 def default @default end |
#name ⇒ String (readonly)
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.
The name of this option.
23 24 25 |
# File 'lib/mongoid/config/introspection.rb', line 23 def name @name end |
Class Method Details
.from_captures(captures) ⇒ 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.
Instantiate an option from an array of Regex captures.
46 47 48 |
# File 'lib/mongoid/config/introspection.rb', line 46 def self.from_captures(captures) new(captures[2], captures[3], captures[1]) end |
Instance Method Details
#==(option) ⇒ true | false
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.
Compare self with the given option.
89 90 91 92 93 |
# File 'lib/mongoid/config/introspection.rb', line 89 def ==(option) name == option.name && default == option.default && comment == option.comment end |
#deprecated? ⇒ true | false
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.
Reports whether or not the text “(Deprecated)” is present in the option’s comment.
81 82 83 |
# File 'lib/mongoid/config/introspection.rb', line 81 def deprecated? comment.include?("(Deprecated)") end |
#indented_comment(indent: 2, indent_first_line: false) ⇒ String
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.
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)
71 72 73 74 75 |
# 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 |