X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdirname.rb;h=54bd9b6f2c2fb404710587673cac6c94ad9ae260;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=40b300d89d3e00f06f7f01e8cf213581c58a3c9d;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb index 40b300d89..54bd9b6f2 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb @@ -1,18 +1,25 @@ +# +# dirname.rb +# module Puppet::Parser::Functions - newfunction(:dirname, :type => :rvalue, :doc => <<-EOS + newfunction(:dirname, :type => :rvalue, :doc => <<-DOC Returns the dirname of a path. - EOS - ) do |arguments| + DOC + ) do |arguments| - if arguments.size < 1 then - raise(Puppet::ParseError, "dirname(): No arguments given") + if arguments.empty? + raise(Puppet::ParseError, 'dirname(): No arguments given') end - if arguments.size > 1 then + if arguments.size > 1 raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})") end unless arguments[0].is_a?(String) raise(Puppet::ParseError, 'dirname(): Requires string as argument') end + # undef is converted to an empty string '' + if arguments[0].empty? + raise(Puppet::ParseError, 'dirname(): Requires a non-empty string as argument') + end return File.dirname(arguments[0]) end