From 5cdf95f85f883b8934ac10809c41d1f68c969863 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 7 Jun 2024 14:53:25 +0200 Subject: [PATCH] Drop deprecated self.get_os_facts() The method got deprecated a long long time ago. --- .rubocop_todo.yml | 11 +++--- lib/facterdb.rb | 31 --------------- lib/facterdb/bin.rb | 2 +- spec/facter_db_spec.rb | 85 ------------------------------------------ 4 files changed, 6 insertions(+), 123 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f2cb0d34..bf571f70 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-06-08 21:54:16 UTC using RuboCop version 1.63.5. +# on 2024-06-10 08:58:13 UTC using RuboCop version 1.63.5. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -63,7 +63,7 @@ RSpec/DescribeClass: - '**/spec/views/**/*' - 'spec/facts_spec.rb' -# Offense count: 12 +# Offense count: 10 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants. # SupportedStyles: described_class, explicit @@ -80,12 +80,12 @@ RSpec/ExampleLength: RSpec/MultipleExpectations: Max: 7 -# Offense count: 19 +# Offense count: 11 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 6 -# Offense count: 11 +# Offense count: 3 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 4 @@ -98,13 +98,12 @@ RSpec/PredicateMatcher: Exclude: - 'spec/facter_db_spec.rb' -# Offense count: 2 +# Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: MinBranchesCount. Style/CaseLikeIf: Exclude: - 'Rakefile' - - 'lib/facterdb.rb' # Offense count: 2 # Configuration parameters: AllowedConstants. diff --git a/lib/facterdb.rb b/lib/facterdb.rb index 661e794d..6370ba79 100644 --- a/lib/facterdb.rb +++ b/lib/facterdb.rb @@ -78,37 +78,6 @@ def self.facterdb_fact_files (external_fact_files + default_fact_files).uniq end - # @deprecated Use {.get_facts} instead. - def self.get_os_facts(facter_version = '*', filter = []) - if facter_version == '*' - if filter.is_a?(Array) - filter_str = filter.map { |f| f.map { |k, v| "#{k}=#{v}" }.join(' and ') }.join(' or ') - elsif filter.is_a?(Hash) - filter_str = filter.map { |k, v| "#{k}=#{v}" }.join(' and ') - elsif filter.is_a?(String) - filter_str = filter - else - raise 'filter must be either an Array a Hash or a String' - end - elsif filter.is_a?(Array) - filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map do |f| - f.map do |k, v| - "#{k}=#{v}" - end.join(' and ') - end.join(' or ')})" - elsif filter.is_a?(Hash) - filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map { |k, v| "#{k}=#{v}" }.join(' and ')})" - elsif filter.is_a?(String) - filter_str = "facterversion=/^#{facter_version}/ and (#{filter})" - else - raise 'filter must be either an Array a Hash or a String' - end - - warn "[DEPRECATION] `get_os_facts` is deprecated. Please use `get_facts(#{filter_str})` instead." - - get_facts(filter_str) - end - # @return [String] the string filter # @param filter [Object] The filter to convert to jgrep string def self.generate_filter_str(filter = nil) diff --git a/lib/facterdb/bin.rb b/lib/facterdb/bin.rb index 663d2028..0884cd72 100644 --- a/lib/facterdb/bin.rb +++ b/lib/facterdb/bin.rb @@ -8,7 +8,7 @@ def initialize(args) end def run - puts JSON.pretty_generate(FacterDB.get_os_facts('*', @args[0])) + puts JSON.pretty_generate(FacterDB.get_facts(@args[0])) end end end diff --git a/spec/facter_db_spec.rb b/spec/facter_db_spec.rb index c6dfff8b..965d389f 100644 --- a/spec/facter_db_spec.rb +++ b/spec/facter_db_spec.rb @@ -197,91 +197,6 @@ end end - describe '.get_os_facts' do - subject(:result) { FacterDB.get_os_facts(facter_version, filter) } - - before do - object = defined?(Warning) ? Warning : Kernel - allow(object).to receive(:warn).and_call_original - allow(object).to receive(:warn).with(a_string_matching(/`get_os_facts` is deprecated/)) - end - - context 'without parameters' do - subject(:result) { FacterDB.get_os_facts } - - include_examples 'returns a result' - end - - context 'when matching all Facter versions' do - let(:facter_version) { '*' } - - context 'with an Array filter' do - let(:filter) { [{ kernel: 'Linux' }] } - - include_examples 'returns a result' - end - - context 'with a Hash filter' do - let(:filter) { { kernel: 'Linux' } } - - include_examples 'returns a result' - end - - context 'with a String filter' do - let(:filter) { 'kernel=Linux' } - - include_examples 'returns a result' - end - - context 'with a filter of an unsupported type' do - let(:filter) { true } - - it 'raises an error' do - expect { result }.to raise_error(/filter must be either/) - end - end - end - - context 'when matching a specific facter version' do - let(:facter_version) { '4.0.52' } - - shared_examples 'returns only the specified version' do - it 'only includes fact sets for the specified version' do - expect(result).to all(include(facterversion: match(/^4\.0/))) - end - end - - context 'with an Array filter' do - let(:filter) { [{ kernel: 'Linux' }] } - - include_examples 'returns a result' - include_examples 'returns only the specified version' - end - - context 'with a Hash filter' do - let(:filter) { { kernel: 'Linux' } } - - include_examples 'returns a result' - include_examples 'returns only the specified version' - end - - context 'with a String filter' do - let(:filter) { 'kernel=Linux' } - - include_examples 'returns a result' - include_examples 'returns only the specified version' - end - - context 'with a filter of an unsupported type' do - let(:filter) { true } - - it 'raises an error' do - expect { result }.to raise_error(/filter must be either/) - end - end - end - end - describe '.valid_filters?' do it 'invalid and false' do expect(FacterDB.valid_filters?('and')).to be_falsey