File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -9,24 +9,24 @@ module Puppet::Parser::Functions
99 EOS
1010 ) do |arguments |
1111 # Two arguments are required
12- raise ( Puppet ::ParseError , "difference (): Wrong number of arguments " +
12+ raise ( Puppet ::ParseError , "dig (): Wrong number of arguments " +
1313 "given (#{ arguments . size } for at least 2)" ) if arguments . size < 2
1414
1515 hash , path , default = *arguments
1616
1717 unless hash . is_a? Hash
18- raise ( Puppet ::ParseError , "first argument must be hash, " <<
18+ raise ( Puppet ::ParseError , "dig(): first argument must be hash, " <<
1919 "given #{ hash . class . name } " )
2020 end
2121
2222 unless path . is_a? Array
23- raise ( Puppet ::ParseError , "first argument must be an array, " <<
23+ raise ( Puppet ::ParseError , "dig(): second argument must be an array, " <<
2424 "given #{ path . class . name } " )
2525 end
2626
2727 path . each { |key | hash = hash [ key ] rescue nil }
2828
29- hash || default
29+ hash . nil? ? default : hash
3030 end
3131end
3232
Original file line number Diff line number Diff line change 99 it { is_expected . to run . with_params ( { "a" => "b" } , [ "a" ] ) . and_return ( "b" ) }
1010 it { is_expected . to run . with_params ( { "a" => { "b" => "c" } } , [ "a" , "b" ] ) . and_return ( "c" ) }
1111 it { is_expected . to run . with_params ( { } , [ "a" , "b" ] , "d" ) . and_return ( "d" ) }
12+ it { is_expected . to run . with_params ( { "a" => false } , [ "a" ] ) . and_return ( false ) }
1213end
You can’t perform that action at this time.
0 commit comments