Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / dirname.rb
1 #
2 # dirname.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:dirname, :type => :rvalue, :doc => <<-DOC
6     Returns the dirname of a path.
7     DOC
8              ) do |arguments|
9
10     if arguments.empty?
11       raise(Puppet::ParseError, 'dirname(): No arguments given')
12     end
13     if arguments.size > 1
14       raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})")
15     end
16     unless arguments[0].is_a?(String)
17       raise(Puppet::ParseError, 'dirname(): Requires string as argument')
18     end
19     # undef is converted to an empty string ''
20     if arguments[0].empty?
21       raise(Puppet::ParseError, 'dirname(): Requires a non-empty string as argument')
22     end
23
24     return File.dirname(arguments[0])
25   end
26 end
27
28 # vim: set ts=2 sw=2 et :