X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fbool2str.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fbool2str.rb;h=be25e0a18d286ec993a28709e02d63dac9228be3;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=37d4a4ef21298d1d1cab4359e5fb51fd282d574d;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;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..be25e0a18 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2str.rb @@ -1,9 +1,8 @@ # # bool2str.rb # - module Puppet::Parser::Functions - newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS + newfunction(:bool2str, :type => :rvalue, :doc => <<-DOC 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 @@ -16,10 +15,21 @@ module Puppet::Parser::Functions bool2str(false, 't', 'f') => 'f' Requires a single boolean as an input. - EOS - ) do |arguments| - unless arguments.size == 1 or arguments.size == 3 + Note that 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 +43,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