summaryrefslogtreecommitdiff
path: root/puppet/modules/common/lib/puppet/parser/functions/basename.rb
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-07-12 16:45:36 -0400
committerMicah <micah@leap.se>2016-07-12 16:45:36 -0400
commit6083b23278927189de58c11bbb5bc7d93ccced24 (patch)
treece771fbca93d6f798a6962b3b2a187078c978554 /puppet/modules/common/lib/puppet/parser/functions/basename.rb
parent1f231f09a9b6911b2ca57ac82235c6028922d54f (diff)
git subrepo clone https://leap.se/git/puppet_common puppet/modules/common
subrepo: subdir: "puppet/modules/common" merged: "ae14962" upstream: origin: "https://leap.se/git/puppet_common" branch: "master" commit: "ae14962" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: I82a15d5ab5c4e8f689f73de4e5ae97557f39b6fb
Diffstat (limited to 'puppet/modules/common/lib/puppet/parser/functions/basename.rb')
-rw-r--r--puppet/modules/common/lib/puppet/parser/functions/basename.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/puppet/modules/common/lib/puppet/parser/functions/basename.rb b/puppet/modules/common/lib/puppet/parser/functions/basename.rb
new file mode 100644
index 00000000..dc725375
--- /dev/null
+++ b/puppet/modules/common/lib/puppet/parser/functions/basename.rb
@@ -0,0 +1,22 @@
+# This function has two modes of operation:
+#
+# basename(string) : string
+#
+# Returns the last component of the filename given as argument, which must be
+# formed using forward slashes ("/") regardless of the separator used on the
+# local file system.
+#
+# basename(string[]) : string[]
+#
+# Returns an array of strings with the basename of each item from the argument.
+#
+module Puppet::Parser::Functions
+ newfunction(:basename, :type => :rvalue) do |args|
+ if args[0].is_a?(Array)
+ args.collect do |a| File.basename(a) end
+ else
+ File.basename(args[0])
+ end
+ end
+end
+