summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/settings.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-12-10 17:52:19 -0600
committerLuke Kanies <luke@madstop.com>2007-12-10 17:52:19 -0600
commit3790ce1c6463e0d44ae0151fdc24000b9d5ede27 (patch)
tree3ba943244dc231db586b606762da7f9563a17c81 /lib/puppet/util/settings.rb
parentb852c2fda0d43ce6437b0464e3458c2a686ed05d (diff)
downloadpuppet-3790ce1c6463e0d44ae0151fdc24000b9d5ede27.tar.gz
puppet-3790ce1c6463e0d44ae0151fdc24000b9d5ede27.tar.xz
puppet-3790ce1c6463e0d44ae0151fdc24000b9d5ede27.zip
Fixing part of #948 -- per-setting hooks are now called
when the configuration file is parsed. The bug is still there, but I'm getting closer.
Diffstat (limited to 'lib/puppet/util/settings.rb')
-rw-r--r--lib/puppet/util/settings.rb53
1 files changed, 38 insertions, 15 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 30968db84..4a802d424 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -297,8 +297,26 @@ class Puppet::Util::Settings
@values[area] = values
end
+ # Determine our environment, if we have one.
+ if @config[:environment]
+ env = self.value(:environment).to_sym
+ else
+ env = "none"
+ end
+
+ # Call any hooks we should be calling.
+ settings_with_hooks.each do |setting|
+ each_source(env) do |source|
+ if value = @values[source][setting.name]
+ setting.handle(value)
+ break
+ end
+ end
+ end
+
# We have to do it in the reverse of the search path,
- # because multiple sections could set the same value.
+ # because multiple sections could set the same value
+ # and I'm too lazy to only set the metadata once.
searchpath.reverse.each do |source|
if meta = @values[source][:_meta]
set_metadata(meta)
@@ -687,21 +705,13 @@ Generated on #{Time.now}.
# Check the cache first. It needs to be a per-environment
# cache so that we don't spread values from one env
# to another.
- if @cache[environment||"none"].include?(param)
- return @cache[environment||"none"][param]
+ if cached = @cache[environment||"none"][param]
+ return cached
end
# See if we can find it within our searchable list of values
val = nil
- searchpath(environment).each do |source|
- # Modify the source as necessary.
- source = case source
- when :name:
- self.name
- else
- source
- end
-
+ each_source(environment) do |source|
# Look for the value. We have to test the hash for whether
# it exists, because the value might be false.
if @values[source].include?(param)
@@ -711,9 +721,7 @@ Generated on #{Time.now}.
end
# If we didn't get a value, use the default
- if val.nil?
- val = @config[param].default
- end
+ val = @config[param].default if val.nil?
# Convert it if necessary
val = convert(val)
@@ -835,6 +843,21 @@ Generated on #{Time.now}.
resources
end
+ # Yield each search source in turn.
+ def each_source(environment)
+ searchpath(environment).each do |source|
+ # Modify the source as necessary.
+ source = self.name if source == :name
+ yield source
+ end
+ end
+
+ # Return all elements that have associated hooks; this is so
+ # we can call them after parsing the configuration file.
+ def settings_with_hooks
+ @config.values.find_all { |setting| setting.respond_to?(:handle) }
+ end
+
# Extract extra setting information for files.
def extract_fileinfo(string)
result = {}