summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRichard Clamp <richardc@unixbeard.net>2011-03-18 00:10:00 +0000
committerJames Turnbull <james@lovedthanlost.net>2011-04-06 03:46:49 +1000
commitd56bca8534bd21c046fd19a7fb2f776fe3e100b4 (patch)
treee5af700326354cc68d80c645c6da1f934a074b7d /lib
parent9f4c5c6ac79821700bf4e6beee81f3d865396f4b (diff)
downloadfacter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.tar.gz
facter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.tar.xz
facter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.zip
refactor the mechanism for allowing for resolution ordering to be influenced
renames Facter::Util::Resolution#length to weight as a more generic mechanism for allowing resolutions to state their importance
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/util/fact.rb4
-rw-r--r--lib/facter/util/loader.rb2
-rw-r--r--lib/facter/util/resolution.rb17
3 files changed, 9 insertions, 14 deletions
diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb
index e78ed97..935b3c1 100644
--- a/lib/facter/util/fact.rb
+++ b/lib/facter/util/fact.rb
@@ -41,9 +41,7 @@ class Facter::Util::Fact
# Immediately sort the resolutions, so that we always have
# a sorted list for looking up values.
- # We always want to look them up in the order of number of
- # confines, so the most restricted resolution always wins.
- @resolves.sort! { |a, b| b.length <=> a.length }
+ @resolves.sort! { |a, b| b.weight <=> a.weight }
return resolve
end
diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb
index b6aa8de..a52012c 100644
--- a/lib/facter/util/loader.rb
+++ b/lib/facter/util/loader.rb
@@ -90,7 +90,7 @@ class Facter::Util::Loader
next if fact and env_name != fact
Facter.add($1) do
- from_environment
+ has_weight 1_000_000
setcode { value }
end
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index 2ca2447..d82fab2 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -85,9 +85,8 @@ class Facter::Util::Resolution
end
end
- # Say this resolution came from the environment
- def from_environment
- @from_environment = true
+ def has_weight(weight)
+ @weight = weight
end
# Create a new resolution mechanism.
@@ -96,15 +95,13 @@ class Facter::Util::Resolution
@confines = []
@value = nil
@timeout = 0
- @from_environment = false
+ @weight = nil
end
- # Return the number of confines.
- def length
- # If the resolution came from an environment variable
- # say we're very very sure about the value of the resolution
- if @from_environment
- 1_000_000_000
+ # Return the importance of this resolution.
+ def weight
+ if @weight
+ @weight
else
@confines.length
end