Class: Middleman::Configuration::ConfigSetting
- Inherits:
-
Object
- Object
- Middleman::Configuration::ConfigSetting
- Defined in:
- middleman-core/lib/middleman-core/configuration.rb
Overview
An individual configuration setting, with an optional default and description. Also models whether or not a value has been set.
Instance Attribute Summary collapse
-
#default ⇒ Object
The default value for this setting.
-
#description ⇒ Object
A human-friendly description of the setting.
-
#key ⇒ Object
The name of this setting.
-
#options ⇒ Object
Additional config.
Instance Method Summary collapse
-
#initialize(key, default, description, options_hash = ::Middleman::EMPTY_HASH) ⇒ ConfigSetting
constructor
A new instance of ConfigSetting.
-
#value ⇒ Object
The effective value of the setting, which may be the default if the user has not set a value themselves.
-
#value=(value) ⇒ Object
The user-supplied value for this setting, overriding the default.
-
#value_set? ⇒ Boolean
Whether or not there has been a value set beyond the default.
Constructor Details
#initialize(key, default, description, options_hash = ::Middleman::EMPTY_HASH) ⇒ ConfigSetting
Returns a new instance of ConfigSetting.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 134 def initialize(key, default, description, = ::Middleman::EMPTY_HASH) @value_set = false @array_wrapped_value = nil @array_wrapped_default = nil self.key = key self.default = default self.description = description self. = @array_wrapped_default = (Set.new(self.default) if self.default && [:set] && self.default.is_a?(Array)) end |
Instance Attribute Details
#default ⇒ Object
The default value for this setting
126 127 128 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 126 def default @default end |
#description ⇒ Object
A human-friendly description of the setting
129 130 131 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 129 def description @description end |
#key ⇒ Object
The name of this setting
123 124 125 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 123 def key @key end |
#options ⇒ Object
Additional config.
132 133 134 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 132 def @options end |
Instance Method Details
#value ⇒ Object
The effective value of the setting, which may be the default if the user has not set a value themselves. Note that even if the user sets the value to nil it will override the default.
157 158 159 160 161 162 163 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 157 def value if value_set? @array_wrapped_value || @value else @array_wrapped_default || default end end |
#value=(value) ⇒ Object
The user-supplied value for this setting, overriding the default
147 148 149 150 151 152 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 147 def value=(value) @value = value @value_set = true @array_wrapped_value = (Set.new(@value) if @value && [:set] && @value.is_a?(Array)) end |
#value_set? ⇒ Boolean
Whether or not there has been a value set beyond the default
166 167 168 |
# File 'middleman-core/lib/middleman-core/configuration.rb', line 166 def value_set? @value_set == true end |