Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / ensure_packages.rb
index 1bf8bf1..f255c03 100644 (file)
@@ -1,20 +1,21 @@
 #
 # ensure_packages.rb
 #
-
 module Puppet::Parser::Functions
-  newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
-Takes a list of packages and only installs them if they don't already exist.
-It optionally takes a hash as a second parameter that will be passed as the
-third argument to the ensure_resource() function.
-    EOS
-  ) do |arguments|
-
-    if arguments.size > 2 or arguments.size == 0
-      raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)")
-    elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
-      raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash')
-    end
+  newfunction(:ensure_packages, :type => :statement, :doc => <<-DOC
+    @summary
+      Takes a list of packages and only installs them if they don't already exist.
+
+    It optionally takes a hash as a second parameter that will be passed as the
+    third argument to the ensure_resource() function.
+
+    @return
+      install the passed packages
+  DOC
+             ) do |arguments|
+
+    raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)") if arguments.size > 2 || arguments.empty?
+    raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') if arguments.size == 2 && !arguments[1].is_a?(Hash)
 
     if arguments[0].is_a?(Hash)
       if arguments[1]
@@ -27,7 +28,7 @@ third argument to the ensure_resource() function.
       end
 
       Puppet::Parser::Functions.function(:ensure_resources)
-      function_ensure_resources(['package', arguments[0].dup, defaults ])
+      function_ensure_resources(['package', arguments[0].dup, defaults])
     else
       packages = Array(arguments[0])
 
@@ -41,12 +42,10 @@ third argument to the ensure_resource() function.
       end
 
       Puppet::Parser::Functions.function(:ensure_resource)
-      packages.each { |package_name|
-      raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.length == 0
-      if !findresource("Package[#{package_name}]")
-        function_ensure_resource(['package', package_name, defaults ])
+      packages.each do |package_name|
+        raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.empty?
+        function_ensure_resource(['package', package_name, defaults])
       end
-    }
     end
   end
 end