File: dirname.rb

package info (click to toggle)
puppet-module-puppetlabs-stdlib 9.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,448 kB
  • sloc: ruby: 3,522; sh: 46; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

#
# dirname.rb
#
module Puppet::Parser::Functions
  newfunction(:dirname, type: :rvalue, doc: <<-DOC
    @summary
      Returns the dirname of a path.

    @return [String] the given path's dirname
  DOC
  ) do |arguments|
    raise(Puppet::ParseError, 'dirname(): No arguments given') if arguments.empty?
    raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})") if arguments.size > 1
    raise(Puppet::ParseError, 'dirname(): Requires string as argument') unless arguments[0].is_a?(String)
    # undef is converted to an empty string ''
    raise(Puppet::ParseError, 'dirname(): Requires a non-empty string as argument') if arguments[0].empty?

    return File.dirname(arguments[0])
  end
end

# vim: set ts=2 sw=2 et :