Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basename.rb conflict with stdlib basename.rb #69

Open
Poil opened this issue Dec 3, 2016 · 1 comment
Open

basename.rb conflict with stdlib basename.rb #69

Poil opened this issue Dec 3, 2016 · 1 comment

Comments

@Poil
Copy link

Poil commented Dec 3, 2016

Hi,

Stdlib also provide a basename.rb

./modules/stdlib/lib/puppet/parser/functions/basename.rb
./modules/glassfish/lib/puppet/parser/functions/basename.rb

On some runs :

Notice: /File[/data/puppet/lib/puppet/parser/functions/basename.rb]/content: 
--- /data/puppet/lib/puppet/parser/functions/basename.rb	2016-12-02 09:26:48.249811558 +0100
+++ /tmp/puppet-file20161203-23755-16hmw6n	2016-12-03 17:54:23.898892747 +0100
@@ -1,34 +1,15 @@
+# basename(string) : string
+# 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.
 module Puppet::Parser::Functions
-  newfunction(:basename, :type => :rvalue, :doc => <<-EOS
-    Strips directory (and optional suffix) from a filename
-    EOS
-  ) do |arguments|
-
-    if arguments.size < 1 then
-      raise(Puppet::ParseError, "basename(): No arguments given")
-    elsif arguments.size > 2 then
-      raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})")
+  newfunction(:basename, :type => :rvalue) do |args|
+    if args[0].is_a?(Array)
+      args.collect do |a| File.basename(a) end
     else
-
-      unless arguments[0].is_a?(String)
-        raise(Puppet::ParseError, 'basename(): Requires string as first argument')
-      end
-
-      if arguments.size == 1 then
-        rv = File.basename(arguments[0])
-      elsif arguments.size == 2 then
-
-        unless arguments[1].is_a?(String)
-          raise(Puppet::ParseError, 'basename(): Requires string as second argument')
-        end
-
-        rv = File.basename(arguments[0], arguments[1])
-      end
-
+      File.basename(args[0])
     end
-
-    return rv
   end
-end
-
-# vim: set ts=2 sw=2 et :
+end
\ No newline at end of file

Notice: /File[/data/puppet/lib/puppet/parser/functions/basename.rb]/content: content changed '{md5}c61952b3f68fd86408c84fca2c3febb1' to '{md5}df195fdf6ee16e19d419e07b96f28fe1'
@fatmcgav
Copy link
Owner

fatmcgav commented Dec 8, 2016

@Poil cheers for reporting. I'll take a look and see if the stdlib function provides the same functionality...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants