diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 23:15:00 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 23:15:00 +0000 |
commit | f3cc5e30a913a9236f6c54e880593ec5a1f8450e (patch) | |
tree | 998b171e6f12a4db2eeacc1e0602a8644f16b865 | |
parent | 01d37d94e8588a7a9dad7311c8b1eeafaf82c7b5 (diff) | |
download | facter-f3cc5e30a913a9236f6c54e880593ec5a1f8450e.tar.gz facter-f3cc5e30a913a9236f6c54e880593ec5a1f8450e.tar.xz facter-f3cc5e30a913a9236f6c54e880593ec5a1f8450e.zip |
Adding the ability to specify tags as hashes or arrays, as requested in #112.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@117 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rw-r--r-- | lib/facter.rb | 20 | ||||
-rw-r--r-- | tests/tc_simple.rb | 43 |
2 files changed, 60 insertions, 3 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index ce99ba7..985b0d2 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -415,8 +415,15 @@ class Facter end # Add a new tag to the resolution mechanism. - def tag(fact,*values) - @tags.push Tag.new(fact,*values) + def tag(*args) + if args[0].is_a? Hash + args[0].each do |fact, values| + @tags.push Tag.new(fact,*values) + end + else + fact = args.shift + @tags.push Tag.new(fact,*args) + end end def to_s @@ -457,8 +464,15 @@ class Facter # Add the tag. Requires the fact name, an operator, and the value # we're comparing to. def initialize(fact, *values) + fact = fact.to_s if fact.is_a? Symbol @fact = fact - @values = values + @values = values.collect do |value| + if value.is_a? String + value + else + value.to_s + end + end end def to_s diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index 8efdbd7..66abf23 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -404,6 +404,49 @@ some random stuff end end + def test_tag_as_array_and_hash + assert_nothing_raised { + Facter.add("myfact") do + tag "kernel", Facter.kernel + setcode do "yep" end + end + } + + assert_equal("yep", Facter.myfact, "Did not get tagged goal") + + # now try it as a hash + assert_nothing_raised { + Facter.add("hashfact") do + tag "kernel" => Facter.kernel + setcode do "hashness" end + end + } + + assert_equal("hashness", Facter.hashfact, "Did not get tagged goal") + + # now with multiple values + assert_nothing_raised { + Facter.add("hashfact2") do + tag :kernel => ["nosuchkernel", Facter.kernel] + setcode do "multihash" end + end + } + + assert_equal("multihash", Facter.hashfact2, "Did not get multivalue tag") + + end + + def test_strings_or_symbols + assert_nothing_raised { + Facter.add("symbol1") do + tag :kernel => Facter.kernel + setcode do "yep1" end + end + } + + assert_equal("yep1", Facter.symbol1, "Did not get symbol fact") + end + if Facter.kernel == "Linux" def test_memoryonlinux assert_nothing_raised { |