facter 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +1 -1
  3. data/lib/docs/generate.rb +1 -6
  4. data/lib/facter/custom_facts/core/directed_graph.rb +2 -4
  5. data/lib/facter/custom_facts/core/execution/base.rb +1 -1
  6. data/lib/facter/custom_facts/core/execution/posix.rb +6 -2
  7. data/lib/facter/custom_facts/core/execution/windows.rb +4 -1
  8. data/lib/facter/custom_facts/core/execution.rb +1 -1
  9. data/lib/facter/custom_facts/core/file_loader.rb +0 -4
  10. data/lib/facter/custom_facts/core/suitable.rb +1 -1
  11. data/lib/facter/custom_facts/util/collection.rb +2 -4
  12. data/lib/facter/custom_facts/util/confine.rb +4 -1
  13. data/lib/facter/custom_facts/util/fact.rb +1 -1
  14. data/lib/facter/custom_facts/util/loader.rb +2 -2
  15. data/lib/facter/custom_facts/util/resolution.rb +8 -4
  16. data/lib/facter/custom_facts/util/values.rb +1 -1
  17. data/lib/facter/facts/amzn/os/distro/release.rb +6 -1
  18. data/lib/facter/facts/amzn/os/release.rb +5 -0
  19. data/lib/facter/facts/linux/dmi/product/version.rb +19 -0
  20. data/lib/facter/facts/linux/kernelmajversion.rb +1 -1
  21. data/lib/facter/facts/macosx/is_virtual.rb +1 -1
  22. data/lib/facter/facts/macosx/virtual.rb +3 -3
  23. data/lib/facter/facts/mariner/os/release.rb +1 -1
  24. data/lib/facter/facts/photon/os/release.rb +1 -1
  25. data/lib/facter/facts/solaris/kernelmajversion.rb +1 -1
  26. data/lib/facter/facts/solaris/ldom.rb +1 -1
  27. data/lib/facter/facts/windows/hypervisors/kvm.rb +1 -1
  28. data/lib/facter/facts/windows/interfaces.rb +1 -1
  29. data/lib/facter/framework/benchmarking/timer.rb +2 -2
  30. data/lib/facter/framework/cli/cli.rb +6 -8
  31. data/lib/facter/framework/cli/cli_launcher.rb +1 -1
  32. data/lib/facter/framework/config/fact_groups.rb +1 -1
  33. data/lib/facter/framework/core/cache_manager.rb +5 -6
  34. data/lib/facter/framework/core/fact_loaders/class_discoverer.rb +4 -3
  35. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +1 -3
  36. data/lib/facter/framework/core/fact_manager.rb +4 -4
  37. data/lib/facter/framework/core/file_loader.rb +736 -733
  38. data/lib/facter/framework/core/options/config_file_options.rb +4 -6
  39. data/lib/facter/framework/formatters/hocon_fact_formatter.rb +3 -2
  40. data/lib/facter/framework/formatters/legacy_fact_formatter.rb +4 -4
  41. data/lib/facter/framework/logging/logger.rb +6 -6
  42. data/lib/facter/framework/logging/logger_helper.rb +10 -11
  43. data/lib/facter/framework/parsers/query_parser.rb +24 -20
  44. data/lib/facter/resolvers/aix/disks.rb +1 -1
  45. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  46. data/lib/facter/resolvers/aix/networking.rb +1 -1
  47. data/lib/facter/resolvers/aix/partitions.rb +2 -2
  48. data/lib/facter/resolvers/aix/serialnumber.rb +1 -1
  49. data/lib/facter/resolvers/amzn/os_release_rpm.rb +40 -0
  50. data/lib/facter/resolvers/dmi.rb +2 -1
  51. data/lib/facter/resolvers/fips_enabled.rb +1 -1
  52. data/lib/facter/resolvers/freebsd/dmi.rb +1 -1
  53. data/lib/facter/resolvers/freebsd/swap_memory.rb +1 -1
  54. data/lib/facter/resolvers/freebsd/system_memory.rb +15 -7
  55. data/lib/facter/resolvers/freebsd/virtual.rb +1 -1
  56. data/lib/facter/resolvers/linux/hostname.rb +1 -1
  57. data/lib/facter/resolvers/macosx/dmi.rb +1 -1
  58. data/lib/facter/resolvers/macosx/filesystems.rb +1 -1
  59. data/lib/facter/resolvers/memory.rb +1 -1
  60. data/lib/facter/resolvers/networking.rb +3 -3
  61. data/lib/facter/resolvers/os_release.rb +1 -1
  62. data/lib/facter/resolvers/partitions.rb +2 -2
  63. data/lib/facter/resolvers/processors_lscpu.rb +2 -2
  64. data/lib/facter/resolvers/solaris/ffi/ffi.rb +2 -2
  65. data/lib/facter/resolvers/solaris/ffi/functions.rb +2 -2
  66. data/lib/facter/resolvers/solaris/mountpoints.rb +1 -1
  67. data/lib/facter/resolvers/solaris/networking.rb +2 -2
  68. data/lib/facter/resolvers/solaris/os_release.rb +2 -2
  69. data/lib/facter/resolvers/uname.rb +10 -6
  70. data/lib/facter/resolvers/virt_what.rb +2 -1
  71. data/lib/facter/resolvers/windows/memory.rb +3 -2
  72. data/lib/facter/resolvers/windows/product_release.rb +7 -7
  73. data/lib/facter/resolvers/xen.rb +3 -1
  74. data/lib/facter/util/aix/info_extractor.rb +1 -1
  75. data/lib/facter/util/aix/odm_query.rb +1 -1
  76. data/lib/facter/util/api_debugger.rb +2 -2
  77. data/lib/facter/util/facts/facts_utils.rb +2 -1
  78. data/lib/facter/util/facts/posix/virtual_detector.rb +8 -5
  79. data/lib/facter/util/facts/unit_converter.rb +2 -2
  80. data/lib/facter/util/file_helper.rb +1 -2
  81. data/lib/facter/util/macosx/system_profile_executor.rb +3 -3
  82. data/lib/facter/util/resolvers/fingerprint.rb +1 -7
  83. data/lib/facter/util/resolvers/networking/networking.rb +4 -3
  84. data/lib/facter/util/resolvers/networking/primary_interface.rb +2 -0
  85. data/lib/facter/util/resolvers/ssh.rb +1 -9
  86. data/lib/facter/util/resolvers/ssh_helper.rb +2 -0
  87. data/lib/facter/util/utils.rb +2 -2
  88. data/lib/facter/version.rb +1 -1
  89. data/lib/facter.rb +7 -0
  90. metadata +11 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb4ad4e8f37099548b19f8b37bc43b11b2f2ba2cfe28df31ffc30b4d8b6aac87
4
- data.tar.gz: d978305277df30b5f97116aab7d96f1935de8e35db2cee3fdab1aa28db694a78
3
+ metadata.gz: 9cde774257133c7283c2bd6a697e8892d2614ee63d89b52d64648eb6cb8e92c2
4
+ data.tar.gz: a24ba725108a86b796e07cfd01f3f9ed11c03558f7fba8df77e213fbc48c3c62
5
5
  SHA512:
6
- metadata.gz: 9a0ebd49f8a7ddae37b97c4c2430b93f3fb18b462203daa6544bdfcdbdc28a3c4f1df5b90bbabb17a17fa2e8a1cef28f467e1b5cad70547c616e95e1051c1688
7
- data.tar.gz: ef0687cb134a6d37e1d4a35ba8047ca134230e0834f5354fc8a3ce6463999b0f237c265b4dbf1d55f45a2cf12276f207f4c5756afd62bbcf2b61abb19ccf0eaa
6
+ metadata.gz: 2fa441a192b26deafd97f2cda183d2aff0194dcdbd40fb7c75c610cb8e3678fbefdd29d16d7f262da3d6e45f89f99a87cdaf305100552e1d8bf4050a4fe7562d
7
+ data.tar.gz: a512d5720fcd1d4af1b4334a1d99831642c0cecf9f0f6a61d37d9561fa83b2eda4f1724c81b2afb324502a7171a77c7b837275f3f8530de872c6fc51d19c9217
data/bin/facter CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pathname'
5
- require 'facter/framework/cli/cli_launcher.rb'
5
+ require 'facter/framework/cli/cli_launcher'
6
6
 
7
7
  Facter::OptionsValidator.validate(ARGV)
8
8
  processed_arguments = CliLauncher.prepare_arguments(ARGV)
data/lib/docs/generate.rb CHANGED
@@ -17,12 +17,7 @@ def format_facts(fact_hash)
17
17
  scope = OpenStruct.new({
18
18
  facts: fact_hash
19
19
  })
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
20
+ erb = ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
26
21
  erb.result(scope.instance_eval { binding })
27
22
  end
28
23
 
@@ -22,10 +22,8 @@ module LegacyFacter
22
22
 
23
23
  alias tsort_each_node each_key
24
24
 
25
- def tsort_each_child(node)
26
- fetch(node, []).each do |child|
27
- yield child
28
- end
25
+ def tsort_each_child(node, &block)
26
+ fetch(node, []).each(&block)
29
27
  end
30
28
 
31
29
  def tsort
@@ -30,7 +30,7 @@ module Facter
30
30
  # use an ensure block to make absolutely sure we restore the variables
31
31
  ensure
32
32
  # restore the old values
33
- values.each do |var, _value|
33
+ values.each_key do |var|
34
34
  if old.include?(var)
35
35
  ENV[var] = old[var]
36
36
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Facter
2
4
  module Core
3
5
  module Execution
@@ -36,7 +38,8 @@ module Facter
36
38
  exe = nil
37
39
  args = nil
38
40
 
39
- if (match = (command.match(DOUBLE_QUOTED_COMMAND) || command.match(SINGLE_QUOTED_COMMAND)))
41
+ match = command.match(DOUBLE_QUOTED_COMMAND) || command.match(SINGLE_QUOTED_COMMAND)
42
+ if match
40
43
  exe, args = match.captures
41
44
  else
42
45
  exe, args = command.split(/ /, 2)
@@ -44,7 +47,8 @@ module Facter
44
47
 
45
48
  return unless exe && (expanded = which(exe))
46
49
 
47
- expanded = "'#{expanded}'" if /\s/.match?(expanded)
50
+ expanded = expanded.dup
51
+ expanded = +"'#{expanded}'" if /\s/.match?(expanded)
48
52
  expanded << " #{args}" if args
49
53
 
50
54
  expanded
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Facter
2
4
  module Core
3
5
  module Execution
@@ -56,7 +58,8 @@ module Facter
56
58
 
57
59
  return unless exe && (expanded = which(exe))
58
60
 
59
- expanded = "\"#{expanded}\"" if /\s+/.match?(expanded)
61
+ expanded = expanded.dup
62
+ expanded = +"\"#{expanded}\"" if /\s+/.match?(expanded)
60
63
  expanded << " #{args}" if args
61
64
 
62
65
  expanded
@@ -3,7 +3,7 @@
3
3
  module Facter
4
4
  module Core
5
5
  module Execution
6
- @@impl = if LegacyFacter::Util::Config.windows?
6
+ @@impl = if LegacyFacter::Util::Config.windows? # rubocop:disable Style/ClassVars
7
7
  Facter::Core::Execution::Windows.new
8
8
  else
9
9
  Facter::Core::Execution::Posix.new
@@ -2,14 +2,12 @@
2
2
 
3
3
  require_relative '../../../facter/custom_facts/util/fact'
4
4
  require_relative '../../../facter/custom_facts/util/collection'
5
- require_relative '../../../facter/custom_facts/util/fact'
6
5
  require_relative '../../../facter/custom_facts/util/loader'
7
6
  require_relative '../../../facter/custom_facts/core/execution/base'
8
7
  require_relative '../../../facter/custom_facts/core/execution/windows'
9
8
  require_relative '../../../facter/custom_facts/core/execution/posix'
10
9
  require_relative '../../../facter/custom_facts/util/values'
11
10
  require_relative '../../../facter/custom_facts/util/confine'
12
-
13
11
  require_relative '../../../facter/custom_facts/util/config'
14
12
 
15
13
  require_relative '../../../facter/custom_facts/util/normalization'
@@ -18,10 +16,8 @@ require_relative '../../../facter/custom_facts/core/resolvable'
18
16
  require_relative '../../../facter/custom_facts/core/suitable'
19
17
  require_relative '../../../facter/custom_facts/util/resolution'
20
18
  require_relative '../../../facter/custom_facts/core/directed_graph'
21
- require_relative '../../../facter/custom_facts/core/resolvable'
22
19
  require_relative '../../../facter/custom_facts/core/aggregate'
23
20
  require_relative '../../../facter/custom_facts/util/composite_loader'
24
21
  require_relative '../../../facter/custom_facts/util/parser'
25
22
  require_relative '../../../facter/custom_facts/util/directory_loader'
26
23
  require_relative '../../../facter/custom_facts/util/nothing_loader'
27
- require_relative '../../../facter/custom_facts/util/nothing_loader'
@@ -18,7 +18,7 @@ module LegacyFacter
18
18
  # @return [void]
19
19
  #
20
20
  # @api public
21
- def has_weight(weight)
21
+ def has_weight(weight) # rubocop:disable Naming/PredicateName
22
22
  @weight = weight
23
23
  self
24
24
  end
@@ -80,7 +80,7 @@ module LegacyFacter
80
80
 
81
81
  # Flush all cached values.
82
82
  def flush
83
- @facts.each { |_name, fact| fact.flush }
83
+ @facts.each_value(&:flush)
84
84
  @external_facts_loaded = nil
85
85
  end
86
86
 
@@ -134,9 +134,7 @@ module LegacyFacter
134
134
  load_external_facts
135
135
  end
136
136
 
137
- attr_reader :internal_loader
138
-
139
- attr_reader :external_loader
137
+ attr_reader :internal_loader, :external_loader
140
138
 
141
139
  # Return a hash of all of our facts.
142
140
  def to_hash
@@ -63,7 +63,10 @@ module LegacyFacter
63
63
  end
64
64
  end
65
65
 
66
- @values.any? { |v| convert(v) === value }
66
+ # we're intentionally using case equality (triple equals) because we
67
+ # support matching against anything that supports === such as ranges,
68
+ # regular expressions, etc
69
+ @values.any? { |v| convert(v) === value } # rubocop:disable Style/CaseEquality
67
70
  end
68
71
 
69
72
  private
@@ -86,7 +86,7 @@ module Facter
86
86
  resolve
87
87
  rescue StandardError => e
88
88
  msg = "Unable to add resolve #{resolution_name.inspect} for fact '#{@name}': #{e.message}"
89
- msg += "\n" + e.backtrace.join("\n") if Options[:trace]
89
+ msg += "\n#{e.backtrace.join("\n")}" if Options[:trace]
90
90
  log.error(msg, true)
91
91
  nil
92
92
  end
@@ -18,7 +18,7 @@ module LegacyFacter
18
18
  shortname = fact.to_s.downcase
19
19
  load_env(shortname)
20
20
 
21
- filename = shortname + '.rb'
21
+ filename = "#{shortname}.rb"
22
22
 
23
23
  paths = search_path
24
24
  paths&.each do |dir|
@@ -40,7 +40,7 @@ module LegacyFacter
40
40
  paths = search_path
41
41
  paths&.each do |dir|
42
42
  # clean the search path of wrong slashes and backslashes
43
- dir = dir.gsub(%r{[\/\\]+}, File::SEPARATOR)
43
+ dir = dir.gsub(%r{[/\\]+}, File::SEPARATOR)
44
44
  # dir is already an absolute path
45
45
  Dir.glob(File.join(dir, '*.rb')).each do |path|
46
46
  # exclude dirs that end with .rb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This represents a fact resolution. A resolution is a concrete
2
4
  # implementation of a fact. A single fact can have many resolutions and
3
5
  # the correct resolution will be chosen at runtime. Each time
@@ -88,7 +90,7 @@ module Facter
88
90
  # @api private
89
91
  def evaluate(&block)
90
92
  if @last_evaluated
91
- msg = "Already evaluated #{@name}"
93
+ msg = +"Already evaluated #{@name}"
92
94
  msg << " at #{@last_evaluated}" if msg.is_a? String
93
95
  msg << ', reevaluating anyways'
94
96
  log.warn msg
@@ -157,9 +159,11 @@ module Facter
157
159
  #
158
160
  # @api private
159
161
  def <=>(other)
160
- return compare_equal_weights(other) if weight == other.weight
161
- return 1 if weight > other.weight
162
- return -1 if weight < other.weight
162
+ if weight == other.weight
163
+ compare_equal_weights(other)
164
+ else
165
+ weight <=> other.weight
166
+ end
163
167
  end
164
168
 
165
169
  private
@@ -90,7 +90,7 @@ module LegacyFacter
90
90
 
91
91
  if structure.is_a? Hash
92
92
  structure.each_pair do |name, value|
93
- new_path = "#{path}_#{name}".gsub(%r{\-|/}, '_')
93
+ new_path = "#{path}_#{name}".gsub(%r{-|/}, '_')
94
94
  results.merge! flatten_structure(new_path, value)
95
95
  end
96
96
  elsif structure.is_a? Array
@@ -20,10 +20,15 @@ module Facts
20
20
  end
21
21
 
22
22
  def determine_release_version
23
+ # For backwards compatibility, use system-release for AL1/AL2
23
24
  version = Facter::Resolvers::ReleaseFromFirstLine.resolve(:release, release_file: '/etc/system-release')
25
+ if !version.nil? && version != '2'
26
+ # Use os-release for AL2023 and up
27
+ version = Facter::Resolvers::Amzn::OsReleaseRpm.resolve(:version)
28
+ end
24
29
  version ||= Facter::Resolvers::OsRelease.resolve(:version_id)
25
30
 
26
- Facter::Util::Facts.release_hash_from_string(version)
31
+ Facter::Util::Facts.release_hash_from_string(version, include_patch: true)
27
32
  end
28
33
  end
29
34
  end
@@ -18,7 +18,12 @@ module Facts
18
18
  end
19
19
 
20
20
  def determine_release_version
21
+ # For backwards compatibility, use system-release for AL1/AL2
21
22
  version = Facter::Resolvers::ReleaseFromFirstLine.resolve(:release, release_file: '/etc/system-release')
23
+ if !version.nil? && version != '2'
24
+ # Use os-release for AL2023 and up
25
+ version = Facter::Resolvers::Amzn::OsReleaseRpm.resolve(:version)
26
+ end
22
27
  version ||= Facter::Resolvers::OsRelease.resolve(:version_id)
23
28
 
24
29
  Facter::Util::Facts.release_hash_from_string(version)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Linux
5
+ module Dmi
6
+ module Product
7
+ class Version
8
+ FACT_NAME = 'dmi.product.version'
9
+ ALIASES = 'productversion'
10
+
11
+ def call_the_resolver
12
+ fact_value = Facter::Resolvers::Linux::DmiBios.resolve(:product_version)
13
+ [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -17,7 +17,7 @@ module Facts
17
17
  versions_split = full_version.split('.')
18
18
  return versions_split[0] if versions_split.length <= 1
19
19
 
20
- versions_split[0] + '.' + versions_split[1]
20
+ "#{versions_split[0]}.#{versions_split[1]}"
21
21
  end
22
22
  end
23
23
  end
@@ -23,7 +23,7 @@ module Facts
23
23
  return 'virtualbox' if boot_rom_version&.start_with?('VirtualBox')
24
24
 
25
25
  subsystem_vendor_id = Facter::Resolvers::Macosx::SystemProfiler.resolve(:subsystem_vendor_id)
26
- return 'parallels' if subsystem_vendor_id&.start_with?('0x1ab8')
26
+ 'parallels' if subsystem_vendor_id&.start_with?('0x1ab8')
27
27
  end
28
28
  end
29
29
  end
@@ -15,17 +15,17 @@ module Facts
15
15
 
16
16
  def check_vmware
17
17
  model_identifier = Facter::Resolvers::Macosx::SystemProfiler.resolve(:model_identifier)
18
- return 'vmware' if model_identifier&.start_with?('VMware')
18
+ 'vmware' if model_identifier&.start_with?('VMware')
19
19
  end
20
20
 
21
21
  def check_virtualbox
22
22
  boot_rom_version = Facter::Resolvers::Macosx::SystemProfiler.resolve(:boot_rom_version)
23
- return 'virtualbox' if boot_rom_version&.start_with?('VirtualBox')
23
+ 'virtualbox' if boot_rom_version&.start_with?('VirtualBox')
24
24
  end
25
25
 
26
26
  def check_parallels
27
27
  subsystem_vendor_id = Facter::Resolvers::Macosx::SystemProfiler.resolve(:subsystem_vendor_id)
28
- return 'parallels' if subsystem_vendor_id&.start_with?('0x1ab8')
28
+ 'parallels' if subsystem_vendor_id&.start_with?('0x1ab8')
29
29
  end
30
30
  end
31
31
  end
@@ -20,7 +20,7 @@ module Facts
20
20
  def from_specific_file
21
21
  version = Facter::Resolvers::SpecificReleaseFile.resolve(:release,
22
22
  { release_file: '/etc/mariner-release',
23
- regex: /CBL\-Mariner ([0-9.]+)/ })
23
+ regex: /CBL-Mariner ([0-9.]+)/ })
24
24
  Facter::Util::Facts.release_hash_from_matchdata(version)
25
25
  end
26
26
 
@@ -25,7 +25,7 @@ module Facts
25
25
 
26
26
  major = version[1].to_s
27
27
  minor = version[2].to_s
28
- version_data = major + '.' + minor
28
+ version_data = "#{major}.#{minor}"
29
29
 
30
30
  {
31
31
  'full' => version_data,
@@ -8,7 +8,7 @@ module Facts
8
8
  def call_the_resolver
9
9
  full_version = Facter::Resolvers::Uname.resolve(:kernelversion)
10
10
  versions_split = full_version.split('.')
11
- major_version = versions_split.length > 2 ? versions_split[0] + '.' + versions_split[1] : versions_split[0]
11
+ major_version = versions_split.length > 2 ? "#{versions_split[0]}.#{versions_split[1]}" : versions_split[0]
12
12
  Facter::ResolvedFact.new(FACT_NAME, major_version)
13
13
  end
14
14
  end
@@ -54,7 +54,7 @@ module Facts
54
54
  def create_resolved_facts_list(fact_value)
55
55
  resolved_facts = [Facter::ResolvedFact.new(FACT_NAME, fact_value)]
56
56
  ALIASES.each do |fact_alias|
57
- key = fact_alias.split('_')[1..-1].map!(&:to_sym)
57
+ key = fact_alias.split('_')[1..].map!(&:to_sym)
58
58
  resolved_facts << Facter::ResolvedFact.new(fact_alias, fact_value.dig(*key), :legacy)
59
59
  end
60
60
 
@@ -29,7 +29,7 @@ module Facts
29
29
 
30
30
  return { openstack: true } if /^OpenStack/.match?(Facter::Resolvers::DMIComputerSystem.resolve(:name))
31
31
 
32
- return { amazon: true } if /^Amazon/.match?(manufacturer)
32
+ { amazon: true } if /^Amazon/.match?(manufacturer)
33
33
  end
34
34
  end
35
35
  end
@@ -9,7 +9,7 @@ module Facts
9
9
  def call_the_resolver
10
10
  fact_value = Facter::Resolvers::Windows::Networking.resolve(:interfaces)
11
11
 
12
- Facter::ResolvedFact.new(FACT_NAME, fact_value ? fact_value.keys.join(',') : nil, :legacy)
12
+ Facter::ResolvedFact.new(FACT_NAME, fact_value&.keys&.join(','), :legacy)
13
13
  end
14
14
  end
15
15
  end
@@ -7,9 +7,9 @@ module Facter
7
7
  module Benchmarking
8
8
  class Timer
9
9
  class << self
10
- def measure(fact_name, prefix_message = '')
10
+ def measure(fact_name, prefix_message = '', &block)
11
11
  if Options[:timing]
12
- time = Benchmark.measure { yield }
12
+ time = Benchmark.measure(&block)
13
13
 
14
14
  log = "fact '#{fact_name}', took: #{time.format('%r')} seconds"
15
15
  prefix_message = "#{prefix_message} " unless prefix_message.empty?
@@ -113,7 +113,7 @@ module Facter
113
113
  negate_options = %w[block cache custom_facts external_facts]
114
114
 
115
115
  template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'man.erb')
116
- erb = ERB.new(File.read(template), nil, '-')
116
+ erb = ERB.new(File.read(template), trim_mode: '-')
117
117
  erb.filename = template
118
118
  puts erb.result(binding)
119
119
  end
@@ -148,7 +148,7 @@ module Facter
148
148
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
149
149
  Facter::Options.init_from_cli(options)
150
150
 
151
- block_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
151
+ block_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..].join
152
152
  block_groups.gsub!(/:\s*\n/, "\n")
153
153
 
154
154
  puts block_groups
@@ -160,7 +160,7 @@ module Facter
160
160
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
161
161
  Facter::Options.init_from_cli(options)
162
162
 
163
- cache_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
163
+ cache_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..].join
164
164
  cache_groups.gsub!(/:\s*\n/, "\n")
165
165
 
166
166
  puts cache_groups
@@ -183,8 +183,6 @@ module Facter
183
183
  Facter::Util::FileHelper.safe_read("#{path}fixtures/facter_help_header")
184
184
  end
185
185
 
186
- IGNORE_OPTIONS = %w[log_level color no_color].freeze
187
-
188
186
  def add_class_options_to_help
189
187
  help_class_options = +''
190
188
  class_options = Cli.class_options
@@ -200,9 +198,9 @@ module Facter
200
198
 
201
199
  def add_commands_to_help
202
200
  help_command_options = +''
203
- Cli.commands
204
- .select { |_k, command_class| command_class.instance_of?(Thor::Command) }
205
- .each do |_k, command|
201
+ Cli.commands.values
202
+ .select { |command_class| command_class.instance_of?(Thor::Command) }
203
+ .each do |command|
206
204
  help_command_options << build_option(
207
205
  command['name'],
208
206
  [command['usage'].split(',')[1]],
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../../../facter/framework/logging/logger.rb'
4
+ require_relative '../../../facter/framework/logging/logger'
5
5
  Facter::Log.output(STDERR)
6
6
  require_relative '../../../facter'
7
7
  require_relative '../../../facter/framework/cli/cli'
@@ -124,7 +124,7 @@ module Facter
124
124
  end
125
125
 
126
126
  def append_s(unit)
127
- return unit + 's' if unit.length > 2 && unit[-1] != 's'
127
+ return "#{unit}s" if unit.length > 2 && unit[-1] != 's'
128
128
 
129
129
  unit
130
130
  end
@@ -43,15 +43,14 @@ module Facter
43
43
 
44
44
  def fact_cache_enabled?(fact_name)
45
45
  fact = @fact_groups.get_fact(fact_name)
46
- cached = if fact
47
- !fact[:ttls].nil?
48
- else
49
- false
50
- end
46
+ if fact
47
+ !fact[:ttls].nil?
48
+ else
49
+ false
50
+ end
51
51
 
52
52
  # fact_group = @fact_groups.get_fact_group(fact_name)
53
53
  # delete_cache(fact_group) if fact_group && !cached
54
- cached
55
54
  end
56
55
 
57
56
  private
@@ -21,9 +21,10 @@ module Facter
21
21
 
22
22
  def find_nested_classes(mod, discovered_classes)
23
23
  mod.constants.each do |constant_name|
24
- if mod.const_get(constant_name).instance_of? Class
25
- discovered_classes << mod.const_get(constant_name)
26
- elsif mod.const_get(constant_name).instance_of? Module
24
+ obj = mod.const_get(constant_name)
25
+ if obj.instance_of? Class
26
+ discovered_classes << obj
27
+ elsif obj.instance_of? Module
27
28
  find_nested_classes(Module.const_get("#{mod.name}::#{constant_name}"), discovered_classes)
28
29
  end
29
30
  end
@@ -100,13 +100,11 @@ module Facter
100
100
 
101
101
  reject_list_core, reject_list_legacy = construct_reject_lists(blocked_facts, facts)
102
102
 
103
- facts = facts.reject do |fact|
103
+ facts.reject do |fact|
104
104
  reject_list_core.include?(fact) || reject_list_core.find do |fact_to_block|
105
105
  fact_to_block.klass == fact.klass
106
106
  end || reject_list_legacy.include?(fact)
107
107
  end
108
-
109
- facts
110
108
  end
111
109
 
112
110
  def construct_reject_lists(blocked_facts, facts)
@@ -25,7 +25,7 @@ module Facter
25
25
 
26
26
  resolved_facts = override_core_facts(internal_facts, external_facts)
27
27
 
28
- resolved_facts = resolved_facts.concat(cached_facts)
28
+ resolved_facts.concat(cached_facts)
29
29
  cache_manager.cache_facts(resolved_facts)
30
30
 
31
31
  FactFilter.new.filter_facts!(resolved_facts, user_query)
@@ -84,7 +84,7 @@ module Facter
84
84
  searched_facts, cached_facts = @cache_manager.resolve_facts(searched_facts)
85
85
 
86
86
  resolved_facts = @internal_fact_mgr.resolve_facts(searched_facts)
87
- resolved_facts = resolved_facts.concat(cached_facts)
87
+ resolved_facts.concat(cached_facts)
88
88
 
89
89
  FactFilter.new.filter_facts!(resolved_facts, user_query)
90
90
 
@@ -101,7 +101,7 @@ module Facter
101
101
  searched_facts, cached_facts = @cache_manager.resolve_facts(searched_facts)
102
102
 
103
103
  resolved_facts = @external_fact_mgr.resolve_facts(searched_facts)
104
- resolved_facts = resolved_facts.concat(cached_facts)
104
+ resolved_facts.concat(cached_facts)
105
105
  resolved_facts if resolved_facts.any?
106
106
  end
107
107
 
@@ -115,7 +115,7 @@ module Facter
115
115
 
116
116
  resolved_facts = @external_fact_mgr.resolve_facts(searched_facts)
117
117
  resolved_facts = override_core_facts(core_facts, resolved_facts)
118
- resolved_facts = resolved_facts.concat(cached_facts)
118
+ resolved_facts.concat(cached_facts)
119
119
 
120
120
  resolved_facts unless resolved_facts.map(&:value).compact.empty?
121
121
  end