Class: Middleman::Configuration::ConfigSetting

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

Instance Method Summary collapse

Constructor Details

#initialize(key, default, description, options_hash = ::Middleman::EMPTY_HASH) ⇒ ConfigSetting


132
133
134
135
136
137
138
139
140
141
142
# File 'middleman-core/lib/middleman-core/configuration.rb', line 132

def initialize(key, default, description, options_hash = ::Middleman::EMPTY_HASH)
  @value_set = false
  @array_wrapped_value = nil
  @array_wrapped_default = nil
  self.key = key
  self.default = default
  self.description = description
  self.options = options_hash

  @array_wrapped_default = (Set.new(self.default) if self.default && options_hash[:set] && self.default.is_a?(Array))
end

Instance Attribute Details

#defaultObject

The default value for this setting


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

def default
  @default
end

#descriptionObject

A human-friendly description of the setting


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

def description
  @description
end

#keyObject

The name of this setting


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

def key
  @key
end

#optionsObject

Additional config.


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

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.


155
156
157
158
159
160
161
# File 'middleman-core/lib/middleman-core/configuration.rb', line 155

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


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

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

  @array_wrapped_value = (Set.new(@value) if @value && options[:set] && @value.is_a?(Array))
end

#value_set?Boolean

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


164
165
166
# File 'middleman-core/lib/middleman-core/configuration.rb', line 164

def value_set?
  @value_set == true
end