Puppet Function: dirname

Defined in:
vendor_modules/stdlib/lib/puppet/parser/functions/dirname.rb
Function type:
Ruby 3.x API

Summary

Returns the dirname of a path.

Overview

dirname()String

Returns:

  • (String)

    the given path's dirname



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'vendor_modules/stdlib/lib/puppet/parser/functions/dirname.rb', line 7

newfunction(:dirname, type: :rvalue, doc: <<-DOC
  @summary
    Returns the dirname of a path.

  @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
    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