]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / dirname.rb
diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/dirname.rb
new file mode 100644 (file)
index 0000000..40b300d
--- /dev/null
@@ -0,0 +1,21 @@
+module Puppet::Parser::Functions
+  newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
+    Returns the dirname of a path.
+    EOS
+  ) do |arguments|
+
+    if arguments.size < 1 then
+      raise(Puppet::ParseError, "dirname(): No arguments given")
+    end
+    if arguments.size > 1 then
+      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
+
+    return File.dirname(arguments[0])
+  end
+end
+
+# vim: set ts=2 sw=2 et :