Skip to content

Commit

Permalink
Drop deprecated self.get_os_facts()
Browse files Browse the repository at this point in the history
The method got deprecated a long long time ago.
  • Loading branch information
bastelfreak committed Jun 10, 2024
1 parent 1a3dad5 commit 5cdf95f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 123 deletions.
11 changes: 5 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
31 changes: 0 additions & 31 deletions lib/facterdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/facterdb/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
85 changes: 0 additions & 85 deletions spec/facter_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cdf95f

Please sign in to comment.