Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / bool2str.rb
index 37d4a4e..f55fcd8 100644 (file)
@@ -1,25 +1,44 @@
 #
 # bool2str.rb
 #
-
 module Puppet::Parser::Functions
-  newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
-    Converts a boolean to a string using optionally supplied arguments. The
-    optional second and third arguments represent what true and false will be
+  newfunction(:bool2str, :type => :rvalue, :doc => <<-DOC
+    @summary
+      Converts a boolean to a string using optionally supplied arguments.
+
+    The optional second and third arguments represent what true and false will be
     converted to respectively. If only one argument is given, it will be
     converted from a boolean to a string containing 'true' or 'false'.
 
-    *Examples:*
+    @return
+      The converted value to string of the given Boolean
+
+    **Examples of usage**
 
-    bool2str(true)                    => 'true'
-    bool2str(true, 'yes', 'no')       => 'yes'
-    bool2str(false, 't', 'f')         => 'f'
+      ```
+        bool2str(true)                    => 'true'
+        bool2str(true, 'yes', 'no')       => 'yes'
+        bool2str(false, 't', 'f')         => 'f'
+      ```
 
     Requires a single boolean as an input.
-    EOS
-  ) do |arguments|
 
-    unless arguments.size == 1 or arguments.size == 3
+    > *Note:*
+      since Puppet 5.0.0 it is possible to create new data types for almost any
+      datatype using the type system and the built-in
+      [`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string)
+      function is used to convert to String with many different format options.
+
+      ```
+        notice(String(false))         # Notices 'false'
+        notice(String(true))          # Notices 'true'
+        notice(String(false, '%y'))   # Notices 'yes'
+        notice(String(true, '%y'))    # Notices 'no'
+      ```
+    DOC
+             ) do |arguments|
+
+    unless arguments.size == 1 || arguments.size == 3
       raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)")
     end
 
@@ -33,8 +52,8 @@ module Puppet::Parser::Functions
       raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with')
     end
 
-    unless [true_string, false_string].all?{|x| x.kind_of?(String)}
-      raise(Puppet::ParseError, "bool2str(): Requires strings to convert to" )
+    unless [true_string, false_string].all? { |x| x.is_a?(String) }
+      raise(Puppet::ParseError, 'bool2str(): Requires strings to convert to')
     end
 
     return value ? true_string : false_string