X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fdsa-puppet.git;a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fclamp.rb;h=1b6e2d292b6b7b616257977a7ab6de69bfd7058d;hp=cbc67dc95f8c3ebb921181961654b46e6a219f28;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb index cbc67dc95..1b6e2d292 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb @@ -3,10 +3,24 @@ # module Puppet::Parser::Functions newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC - Clamps value to a range. + @summary + Keeps value within the range [Min, X, Max] by sort based on integer value + (parameter order doesn't matter). - Note: From Puppet 6.0.0 this can be done with only core Puppet like this: - [$minval, $maxval, $value_to_clamp].sort[1] + Strings are converted and compared numerically. Arrays of values are flattened + into a list for further handling. + + @example Example usage + + clamp('24', [575, 187])` returns 187. + clamp(16, 88, 661)` returns 88. + clamp([4, 3, '99'])` returns 4. + + > *Note:* + From Puppet 6.0.0 this can be done with only core Puppet like this: + `[$minval, $maxval, $value_to_clamp].sort[1]` + + @return [Array[Integer]] The sorted Array DOC ) do |args|