Mercurial > repos > other > Puppet
diff modules/stdlib/lib/puppet/parser/functions/any2bool.rb @ 478:adf6fe9bbc17
Update Puppet modules to latest versions
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 29 Aug 2024 18:47:29 +0100 |
parents | d9352a684e62 |
children |
line wrap: on
line diff
--- a/modules/stdlib/lib/puppet/parser/functions/any2bool.rb Tue Aug 27 13:35:17 2024 +0100 +++ b/modules/stdlib/lib/puppet/parser/functions/any2bool.rb Thu Aug 29 18:47:29 2024 +0100 @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # any2bool.rb # module Puppet::Parser::Functions - newfunction(:any2bool, :type => :rvalue, :doc => <<-DOC + newfunction(:any2bool, type: :rvalue, doc: <<-DOC @summary Converts 'anything' to a boolean. @@ -19,37 +21,29 @@ @return [Boolean] The boolean value of the object that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? # If argument is already Boolean, return it - if !!arguments[0] == arguments[0] # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean - return arguments[0] - end + return arguments[0] if !!arguments[0] == arguments[0] # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean arg = arguments[0] - if arg.nil? - return false - end + return false if arg.nil? - if arg == :undef - return false - end + return false if arg == :undef valid_float = begin - !!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean - rescue - false - end + !!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean + rescue StandardError + false + end - if arg.is_a?(Numeric) - return function_num2bool([arguments[0]]) - end + return function_num2bool([arguments[0]]) if arg.is_a?(Numeric) if arg.is_a?(String) return function_num2bool([arguments[0]]) if valid_float + return function_str2bool([arguments[0]]) end