diff options
-rw-r--r-- | lib/puppet/functions/fact.rb | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/lib/puppet/functions/fact.rb b/lib/puppet/functions/fact.rb index 48d0d3c..dfb048b 100644 --- a/lib/puppet/functions/fact.rb +++ b/lib/puppet/functions/fact.rb @@ -18,27 +18,22 @@ Puppet::Functions.create_function(:fact) do param 'String', :fact_name end - dispatch :alternative do - param 'Hash', :fact_hash - param 'String', :fact_name + def to_dot_syntax(array_path) + array_path.map do |string| + string.include?('.') ? %Q{"#{string}"} : string + end.join('.') end def fact(fact_name) - dot_dig(closure_scope['facts'], fact_name) - end - - def alternative(alternative_hash, fact_name) - dot_dig(alternative_hash, fact_name) - end + facts = closure_scope['facts'] - def dot_dig(fact_hash, fact_name) # Transform the dot-notation string into an array of paths to walk. Make # sure to correctly extract double-quoted values containing dots as single # elements in the path. path = fact_name.scan(/([^."]+)|(?:")([^"]+)(?:")/).map {|x| x.compact.first } walked_path = [] - path.reduce(fact_hash) do |d, k| + path.reduce(facts) do |d, k| return nil if d.nil? || k.nil? case @@ -60,10 +55,4 @@ Puppet::Functions.create_function(:fact) do result end end - - def to_dot_syntax(array_path) - array_path.map do |string| - string.include?('.') ? %Q{"#{string}"} : string - end.join('.') - end end |