From 6c54cc4e547e17c7e792986645feb0ecbefbe88b Mon Sep 17 00:00:00 2001 From: martyewings Date: Thu, 7 Dec 2023 13:06:23 +0000 Subject: [PATCH] (maint) Unnest module and class names in Ruby tasks --- .rubocop.yml | 3 +- .sync.yml | 2 + files/rb_task_helper.rb | 105 +++++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index deacdc1c..f033404f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,8 +37,7 @@ Style/BlockDelimiters: be consistent then. EnforcedStyle: braces_for_chaining Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact + Enabled: false Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty diff --git a/.sync.yml b/.sync.yml index 1f4d65be..2f3ef267 100644 --- a/.sync.yml +++ b/.sync.yml @@ -7,6 +7,8 @@ Enabled: false RSpec/SubjectStub: Enabled: false + Style/ClassAndModuleChildren: + Enabled: false Gemfile: optional: ":development": diff --git a/files/rb_task_helper.rb b/files/rb_task_helper.rb index 74778379..d8d135a0 100644 --- a/files/rb_task_helper.rb +++ b/files/rb_task_helper.rb @@ -1,59 +1,62 @@ # frozen_string_literal: true # Puppet Agent task helper -module PuppetAgent::RbTaskHelper - private - - def error_result(error_type, error_message) - { - '_error' => { - 'msg' => error_message, - 'kind' => error_type, - 'details' => {}, - }, - } - end - - def puppet_bin_present? - File.exist?(puppet_bin) - end - - # Returns the path to the Puppet agent executable - def puppet_bin - @puppet_bin ||= if Puppet.features.microsoft_windows? - puppet_bin_windows - else - '/opt/puppetlabs/bin/puppet' - end - end - - # Returns the path to the Puppet agent executable on Windows - def puppet_bin_windows - require 'win32/registry' - - install_dir = begin - Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg| - # Rescue missing key - dir = begin - reg['RememberedInstallDir64'] - rescue StandardError - '' - end - # Both keys may exist, make sure the dir exists - break dir if File.exist?(dir) - - # Rescue missing key - begin - reg['RememberedInstallDir'] - rescue StandardError - '' +module PuppetAgent + # Puppet Agent Ruby task helper + module RbTaskHelper + private + + def error_result(error_type, error_message) + { + '_error' => { + 'msg' => error_message, + 'kind' => error_type, + 'details' => {}, + }, + } + end + + def puppet_bin_present? + File.exist?(puppet_bin) + end + + # Returns the path to the Puppet agent executable + def puppet_bin + @puppet_bin ||= if Puppet.features.microsoft_windows? + puppet_bin_windows + else + '/opt/puppetlabs/bin/puppet' + end + end + + # Returns the path to the Puppet agent executable on Windows + def puppet_bin_windows + require 'win32/registry' + + install_dir = begin + Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg| + # Rescue missing key + dir = begin + reg['RememberedInstallDir64'] + rescue StandardError + '' + end + # Both keys may exist, make sure the dir exists + break dir if File.exist?(dir) + + # Rescue missing key + begin + reg['RememberedInstallDir'] + rescue StandardError + '' + end end + rescue Win32::Registry::Error + # Rescue missing registry path + '' end - rescue Win32::Registry::Error - # Rescue missing registry path - '' - end - File.join(install_dir, 'bin', 'puppet.bat') + File.join(install_dir, 'bin', 'puppet.bat') + end end end