X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdirname.rb;h=ae579e20e3bf1a699ce0b5b1b0fc432d3ad6320f;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=40b300d89d3e00f06f7f01e8cf213581c58a3c9d;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;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..ae579e20e 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb @@ -1,18 +1,28 @@ +# +# dirname.rb +# module Puppet::Parser::Functions - newfunction(:dirname, :type => :rvalue, :doc => <<-EOS - Returns the dirname of a path. - EOS - ) do |arguments| + newfunction(:dirname, :type => :rvalue, :doc => <<-DOC + @summary + Returns the dirname of a path. - if arguments.size < 1 then - raise(Puppet::ParseError, "dirname(): No arguments given") + @return [String] the given path's dirname + DOC + ) do |arguments| + + 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