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 7, 2024
1 parent 9c33730 commit 0bdc2f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 141 deletions.
36 changes: 12 additions & 24 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 2023-12-12 12:48:14 UTC using RuboCop version 1.57.2.
# on 2024-06-07 12:53:09 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 All @@ -20,11 +20,12 @@ Lint/SuppressedException:

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessAssignment:
Exclude:
- 'spec/facts_spec.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Expand All @@ -38,7 +39,7 @@ Performance/MapCompact:
Exclude:
- 'lib/facterdb.rb'

# Offense count: 7
# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/StringInclude:
Exclude:
Expand All @@ -62,9 +63,9 @@ 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.
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
Expand All @@ -75,16 +76,16 @@ RSpec/DescribedClass:
RSpec/ExampleLength:
Max: 9

# Offense count: 4
# Offense count: 3
RSpec/MultipleExpectations:
Max: 7

# Offense count: 11
# Offense count: 3
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 6

# Offense count: 11
# Offense count: 3
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4
Expand All @@ -97,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 All @@ -114,7 +114,7 @@ Style/Documentation:
- 'lib/facterdb.rb'
- 'lib/facterdb/bin.rb'

# Offense count: 13
# Offense count: 12
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Expand Down Expand Up @@ -147,12 +147,6 @@ Style/HashTransformKeys:
Exclude:
- 'lib/facterdb.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/facterdb.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapToHash:
Expand Down Expand Up @@ -189,12 +183,6 @@ Style/OptionalBooleanParameter:
Exclude:
- 'lib/facterdb.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'Rakefile'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Expand All @@ -215,4 +203,4 @@ Style/SymbolProc:
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 179
Max: 154
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) { [{ osfamily: 'Debian' }] }

include_examples 'returns a result'
end

context 'with a Hash filter' do
let(:filter) { { osfamily: 'Debian' } }

include_examples 'returns a result'
end

context 'with a String filter' do
let(:filter) { 'osfamily=Debian' }

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) { [{ osfamily: 'Debian' }] }

include_examples 'returns a result'
include_examples 'returns only the specified version'
end

context 'with a Hash filter' do
let(:filter) { { osfamily: 'Debian' } }

include_examples 'returns a result'
include_examples 'returns only the specified version'
end

context 'with a String filter' do
let(:filter) { 'osfamily=Debian' }

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 0bdc2f7

Please sign in to comment.