Update stdlib and concat to 6.1.0 both
[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     @summary
7       Returns the dirname of a path.
8
9     @return [String] the given path's dirname
10     DOC
11              ) do |arguments|
12
13     if arguments.empty?
14       raise(Puppet::ParseError, 'dirname(): No arguments given')
15     end
16     if arguments.size > 1
17       raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})")
18     end
19     unless arguments[0].is_a?(String)
20       raise(Puppet::ParseError, 'dirname(): Requires string as argument')
21     end
22     # undef is converted to an empty string ''
23     if arguments[0].empty?
24       raise(Puppet::ParseError, 'dirname(): Requires a non-empty string as argument')
25     end
26
27     return File.dirname(arguments[0])
28   end
29 end
30
31 # vim: set ts=2 sw=2 et :