X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fclamp.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fclamp.rb;h=cbc67dc95f8c3ebb921181961654b46e6a219f28;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=c4503fe5be12e37c379ca8cec7287892eceeca9b;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb index c4503fe5b..cbc67dc95 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/clamp.rb @@ -1,12 +1,14 @@ # # clamp.rb # - module Puppet::Parser::Functions - newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-EOS + newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC Clamps value to a range. - EOS - ) do |args| + + Note: From Puppet 6.0.0 this can be done with only core Puppet like this: + [$minval, $maxval, $value_to_clamp].sort[1] + DOC + ) do |args| args.flatten! @@ -15,15 +17,15 @@ module Puppet::Parser::Functions # check values out args.each do |value| case [value.class] - when [String] - raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ /^\d+$/ - when [Hash] - raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})") + when [String] + raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ %r{^\d+$} + when [Hash] + raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})") end end # convert to numeric each element # then sort them and get a middle value - args.map{ |n| n.to_i }.sort[1] + args.map { |n| n.to_i }.sort[1] end end