From 51de0c7b67cd2c91e29f8771f0ff3822d3bea61d Mon Sep 17 00:00:00 2001 From: martyewings Date: Tue, 25 Apr 2023 16:08:21 +0100 Subject: [PATCH] Remove deprecated is_array function --- lib/puppet/functions/is_array.rb | 29 ------------------- lib/puppet/parser/functions/is_array.rb | 29 ------------------- spec/functions/is_array_spec.rb | 37 ------------------------- 3 files changed, 95 deletions(-) delete mode 100644 lib/puppet/functions/is_array.rb delete mode 100644 lib/puppet/parser/functions/is_array.rb delete mode 100644 spec/functions/is_array_spec.rb diff --git a/lib/puppet/functions/is_array.rb b/lib/puppet/functions/is_array.rb deleted file mode 100644 index 0a53e07e2..000000000 --- a/lib/puppet/functions/is_array.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_array) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - dispatch :deprecation_gen do - param 'Any', :scope - repeated_param 'Any', :args - end - # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff - # -c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1. - def call(scope, *args) - manipulated_args = [scope] + args - self.class.dispatcher.dispatch(self, scope, manipulated_args) - end - - def deprecation_gen(scope, *args) - call_function('deprecation', 'is_array', 'This method is deprecated, please use match expressions with Stdlib::Compat::Array instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.') - scope.send('function_is_array', args) - end -end diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb deleted file mode 100644 index e4e7b8102..000000000 --- a/lib/puppet/parser/functions/is_array.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# -# is_array.rb -# -module Puppet::Parser::Functions - newfunction(:is_array, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is an array. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - function_deprecation([:is_array, 'This method is deprecated, please use the stdlib validate_legacy function, - with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.']) - - raise(Puppet::ParseError, "is_array(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - type = arguments[0] - - result = type.is_a?(Array) - - return result - end -end diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb deleted file mode 100644 index 63561600f..000000000 --- a/spec/functions/is_array_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_array' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params([]).and_return(true) } - it { is_expected.to run.with_params(['one']).and_return(true) } - it { is_expected.to run.with_params([1]).and_return(true) } - it { is_expected.to run.with_params([{}]).and_return(true) } - it { is_expected.to run.with_params([[]]).and_return(true) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params(1).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(['1.2.3.4']).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(['1.2.3.4']).and_return(true) - end - end -end