Skip to content

Commit 33ca1c0

Browse files
author
Maksym Melnychok
committed
fix error messages, fix returning falsey values
1 parent 06d2016 commit 33ca1c0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/puppet/parser/functions/dig.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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
3131
end
3232

spec/functions/dig_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
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) }
1213
end

0 commit comments

Comments
 (0)