X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fabs.rb;h=5625b984c6bfb72aad5abb44e81e69c41cc40015;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=11d2d7feade35fa8056d8e9b3d4019753959bcd1;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb index 11d2d7fea..5625b984c 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb @@ -1,28 +1,35 @@ # # abs.rb # - module Puppet::Parser::Functions - newfunction(:abs, :type => :rvalue, :doc => <<-EOS - Returns the absolute value of a number, for example -34.56 becomes - 34.56. Takes a single integer and float value as an argument. - EOS - ) do |arguments| + newfunction(:abs, :type => :rvalue, :doc => <<-DOC + @summary + **Deprecated:** Returns the absolute value of a number + + For example -34.56 becomes 34.56. + Takes a single integer or float value as an argument. + + > *Note:* + **Deprected** from Puppet 6.0.0, the built-in + ['abs'](https://puppet.com/docs/puppet/6.4/function.html#abs)function will be used instead. + + @return The absolute value of the given number if it was an Integer + + DOC + ) do |arguments| - raise(Puppet::ParseError, "abs(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 + raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] # Numbers in Puppet are often string-encoded which is troublesome ... if value.is_a?(String) - if value.match(/^-?(?:\d+)(?:\.\d+){1}$/) + if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$} value = value.to_f - elsif value.match(/^-?\d+$/) + elsif value =~ %r{^-?\d+$} value = value.to_i else - raise(Puppet::ParseError, 'abs(): Requires float or ' + - 'integer to work with') + raise(Puppet::ParseError, 'abs(): Requires float or integer to work with') end end