Class: Middleman::Configuration::ConfigSetting

Inherits:
Object
  • Object
show all
Defined in:
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

Instance Method Summary collapse

Constructor Details

#initialize(key, default, description, options = {}) ⇒ ConfigSetting

Returns a new instance of ConfigSetting.



130
131
132
133
134
135
136
# File 'lib/middleman-core/configuration.rb', line 130

def initialize(key, default, description, options={})
  @value_set = false
  self.key = key
  self.default = default
  self.description = description
  self.options = options
end

Instance Attribute Details

#defaultObject

The default value for this setting



122
123
124
# File 'lib/middleman-core/configuration.rb', line 122

def default
  @default
end

#descriptionObject

A human-friendly description of the setting



125
126
127
# File 'lib/middleman-core/configuration.rb', line 125

def description
  @description
end

#keyObject

The name of this setting



119
120
121
# File 'lib/middleman-core/configuration.rb', line 119

def key
  @key
end

#optionsObject

Additional config.



128
129
130
# File 'lib/middleman-core/configuration.rb', line 128

def options
  @options
end

Instance Method Details

#valueObject

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.



147
148
149
# File 'lib/middleman-core/configuration.rb', line 147

def value
  value_set? ? @value : default
end

#value=(value) ⇒ Object

The user-supplied value for this setting, overriding the default



139
140
141
142
# File 'lib/middleman-core/configuration.rb', line 139

def value=(value)
  @value = value
  @value_set = true
end

#value_set?Boolean

Whether or not there has been a value set beyond the default

Returns:

  • (Boolean)


152
153
154
# File 'lib/middleman-core/configuration.rb', line 152

def value_set?
  @value_set == true
end