Skip to content

Commit d356db4

Browse files
authored
Merge pull request #2686 from mhashizume/maint/main/revert-ruby-2.5
Re-add Ruby 2.5 support
2 parents 0d2dcdb + 5e6c601 commit d356db4

File tree

14 files changed

+32
-33
lines changed

14 files changed

+32
-33
lines changed

Diff for: .github/workflows/unit_tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
ruby:
21-
- '2.6'
21+
- '2.5'
2222
- '2.7'
2323
- '3.0'
2424
- '3.2'

Diff for: .rubocop.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
inherit_from: .rubocop_todo.yml
33

44
AllCops:
5-
TargetRubyVersion: 2.6
5+
TargetRubyVersion: 2.5
66
Exclude:
77
- acceptance/**/*
88
- vendor/**/*
@@ -88,6 +88,9 @@ RSpec/MessageSpies:
8888
RSpec/MultipleExpectations:
8989
Max: 3
9090

91+
RSpec/MultipleMemoizedHelpers:
92+
Enabled: false
93+
9194
RSpec/NestedGroups:
9295
Enabled: 6
9396

Diff for: README.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Test Coverage](https://api.codeclimate.com/v1/badges/3bd4be86f4b0b49bc0ca/test_coverage)](https://codeclimate.com/github/puppetlabs/facter/test_coverage)
1010
[![Maintainability](https://api.codeclimate.com/v1/badges/3bd4be86f4b0b49bc0ca/maintainability)](https://codeclimate.com/github/puppetlabs/facter/maintainability)
1111

12+
1213
Facter is a command-line tool that gathers basic facts about nodes (systems)
1314
such as hardware details, network settings, OS type and version, and more.
1415
These facts are made available as variables in your Puppet manifests and can be
@@ -20,20 +21,17 @@ Documentation for the Facter project can be found on the [Puppet Docs
2021
site](https://puppet.com/docs/puppet/latest/facter.html).
2122

2223
## Supported platforms
23-
2424
* Linux
2525
* macOS
2626
* Windows
2727
* Solaris
2828
* AIX
2929

3030
## Requirements
31-
32-
* Ruby 2.6+
31+
* Ruby 2.5+
3332
* FFI (for facts like `mountpoints` which are resolved using C API calls)
3433

3534
## Basic concepts
36-
3735
The project has three main parts, the framework, facts and resolvers.
3836
In the framework we implement functionality that is agnostic of specific facts like parsing user input, formatting output, etc.
3937

@@ -54,10 +52,9 @@ sequenceDiagram
5452
resolver->>fact: system information
5553
fact->>framework: fact value
5654
framework->>user: formatted user output
57-
```
55+
````
5856
5957
## Getting started
60-
6158
After cloning the project, run `bundle install` to install all dependencies.
6259
6360
You can run facter by executing `./bin/facter`.
@@ -66,13 +63,11 @@ The command will output all the facts that facter detected for the current OS.
6663
The implementation can be validated locally by running `bundle exec rake check`.
6764
6865
## Goals - fast, easy, compatible
69-
7066
* Gain performance similar to the C++ version of Facter. We plan to achieve this goal by gathering multiple facts with only one call and by using the faster Win32 API rather than WMI for the Windows implementation.
7167
* Facilitate community contribution. At the moment, C++ presents a possible impediment for community contributions.
7268
* Enable native integration with other Ruby-based projects such as Bolt and puppet.
7369
* Enable native integration for custom facts.
7470
* Provide 100% compatibility with C++ Facter (drop-in replacement).
7571
7672
## Licensing
77-
7873
See [LICENSE](https://github.com/puppetlabs/facter/blob/main/LICENSE) file. Puppet is licensed by Puppet, Inc. under the Apache license. Puppet, Inc. can be contacted at: [email protected]

Diff for: ext/project_data.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gem_require_path: 'lib'
1212
gem_executables: 'facter'
1313
gem_license: 'Apache-2.0'
1414
gem_default_executables: 'facter'
15-
gem_required_ruby_version: ['>= 2.6', '< 4.0']
15+
gem_required_ruby_version: ['>= 2.5', '< 4.0']
1616
gem_runtime_dependencies:
1717
hocon: ~> 1.3
18-
thor: ['>= 1.0.1', '< 2.0']
18+
thor: ['>= 1.0.1', '< 1.3']

Diff for: facter.gemspec

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
2424
base = "#{__dir__}#{File::SEPARATOR}"
2525
spec.files = dirs.map { |path| path.sub(base, '') }
2626

27-
spec.required_ruby_version = '>= 2.6', '< 4.0'
27+
spec.required_ruby_version = '>= 2.5', '< 4.0'
2828
spec.bindir = 'bin'
2929
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
3030
spec.require_paths = ['lib']
@@ -37,14 +37,14 @@ Gem::Specification.new do |spec|
3737
spec.add_development_dependency 'ffi', '1.15.5'
3838
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
3939
spec.add_development_dependency 'rspec', '~> 3.0'
40-
spec.add_development_dependency 'rubocop', '~> 1.50' # last version to support 2.6
41-
spec.add_development_dependency 'rubocop-performance', '~> 1.17'
42-
spec.add_development_dependency 'rubocop-rspec', '~> 2.20'
40+
spec.add_development_dependency 'rubocop', '~> 1.28' # last version to support 2.5
41+
spec.add_development_dependency 'rubocop-performance', '~> 1.5.2'
42+
spec.add_development_dependency 'rubocop-rspec', '~> 2.10' # last version to support 2.5
4343
spec.add_development_dependency 'simplecov', '~> 0.17.1'
4444
spec.add_development_dependency 'sys-filesystem', '~> 1.4'
4545
spec.add_development_dependency 'webmock', '~> 3.12'
4646
spec.add_development_dependency 'yard', '~> 0.9'
4747

4848
spec.add_runtime_dependency 'hocon', '~> 1.3'
49-
spec.add_runtime_dependency 'thor', ['>= 1.0.1', '< 2.0']
49+
spec.add_runtime_dependency 'thor', ['>= 1.0.1', '< 1.3'] # Thor 1.3.0 drops support for Ruby 2.5
5050
end

Diff for: install.rb

-4
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,11 @@ def prepare_installation
208208
# Join two paths. On Windows, dir must be converted to a relative path,
209209
# by stripping the drive letter, but only if the basedir is not empty.
210210
#
211-
# We can't use endless ranges here because we still use older Rubies when building puppet-agent on older platforms
212-
# (such as Solaris 10).
213-
# rubocop:disable Style/SlicingWithRange
214211
def join(basedir, dir)
215212
return "#{basedir}#{dir[2..-1]}" if windows? && !basedir.empty? && (dir.length > 2)
216213

217214
"#{basedir}#{dir}"
218215
end
219-
# rubocop:enable Style/SlicingWithRange
220216

221217
##
222218
# Install file(s) from ./bin to RbConfig::CONFIG['bindir']. Patch it on the way

Diff for: lib/docs/generate.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ def format_facts(fact_hash)
1717
scope = OpenStruct.new({
1818
facts: fact_hash
1919
})
20-
erb = ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
20+
21+
erb = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
22+
ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
23+
else
24+
ERB.new(File.read(PATH_TO_TEMPLATE), nil, '-')
25+
end
2126
erb.result(scope.instance_eval { binding })
2227
end
2328

Diff for: lib/facter/facts/solaris/ldom.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def resolve(key)
5454
def create_resolved_facts_list(fact_value)
5555
resolved_facts = [Facter::ResolvedFact.new(FACT_NAME, fact_value)]
5656
ALIASES.each do |fact_alias|
57-
key = fact_alias.split('_')[1..].map!(&:to_sym)
57+
key = fact_alias.split('_')[1..-1].map!(&:to_sym)
5858
resolved_facts << Facter::ResolvedFact.new(fact_alias, fact_value.dig(*key), :legacy)
5959
end
6060

Diff for: lib/facter/framework/cli/cli.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def man(*args)
113113
negate_options = %w[block cache custom_facts external_facts]
114114

115115
template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'man.erb')
116-
erb = ERB.new(File.read(template), trim_mode: '-')
116+
erb = ERB.new(File.read(template), nil, '-')
117117
erb.filename = template
118118
puts erb.result(binding)
119119
end
@@ -148,7 +148,7 @@ def list_block_groups
148148
options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
149149
Facter::Options.init_from_cli(options)
150150

151-
block_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..].join
151+
block_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
152152
block_groups.gsub!(/:\s*\n/, "\n")
153153

154154
puts block_groups
@@ -160,7 +160,7 @@ def list_cache_groups
160160
options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
161161
Facter::Options.init_from_cli(options)
162162

163-
cache_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..].join
163+
cache_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
164164
cache_groups.gsub!(/:\s*\n/, "\n")
165165

166166
puts cache_groups

Diff for: lib/facter/resolvers/aix/serialnumber.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def read_serialnumber(fact_name)
2222

2323
result.each_line do |line|
2424
if line.include?('value')
25-
@fact_list[:serialnumber] = line.split('=')[1].strip.delete('\"')[6..]
25+
@fact_list[:serialnumber] = line.split('=')[1].strip.delete('\"')[6..-1]
2626
break
2727
end
2828
end

Diff for: lib/facter/resolvers/freebsd/swap_memory.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def post_resolve(fact_name, _options)
1515

1616
def read_swap_memory(fact_name)
1717
output = Facter::Core::Execution.execute('swapinfo -k', logger: log)
18-
data = output.split("\n")[1..].map { |line| line.split(/\s+/) }
18+
data = output.split("\n")[1..-1].map { |line| line.split(/\s+/) }
1919

2020
unless data.empty?
2121
@fact_list[:total_bytes] = kilobytes_to_bytes(data.map { |line| line[1].to_i }.inject(:+))

Diff for: lib/facter/resolvers/networking.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def clean_up_interfaces_response(response)
4444

4545
def parse_interfaces_response(response)
4646
parsed_interfaces_data = {}
47-
interfaces_data = Hash[*response.split(/^([A-Za-z0-9_.]+): /)[1..]]
47+
interfaces_data = Hash[*response.split(/^([A-Za-z0-9_.]+): /)[1..-1]]
4848

4949
interfaces_data.each do |interface_name, raw_data|
5050
parsed_interface_data = {}

Diff for: lib/facter/resolvers/partitions.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def available?(command, blkid_and_lsblk)
112112

113113
def execute_and_extract_blkid_info
114114
stdout = Facter::Core::Execution.execute('blkid', logger: log)
115-
output_hash = Hash[*stdout.split(/^([^:]+):/)[1..]]
115+
output_hash = Hash[*stdout.split(/^([^:]+):/)[1..-1]]
116116
output_hash.each do |key, value|
117-
output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..]]
117+
output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..-1]]
118118
end
119119
end
120120

Diff for: lib/facter/util/api_debugger.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def self.parse_options(options)
3434

3535
options.split(',').each do |option|
3636
if option.start_with?('-')
37-
exclude << option[1..].to_sym
37+
exclude << option[1..-1].to_sym
3838
elsif option.start_with?('+')
39-
print_caller << option[1..].to_sym
39+
print_caller << option[1..-1].to_sym
4040
end
4141
end
4242

0 commit comments

Comments
 (0)