X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fbool2str.rb;h=f55fcd8351645f2fac5cf7c218d85b700abb5cae;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=37d4a4ef21298d1d1cab4359e5fb51fd282d574d;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb index 37d4a4ef2..f55fcd835 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb @@ -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