Skip to content

Commit

Permalink
Merge pull request #687 from MartyEwings/main
Browse files Browse the repository at this point in the history
(maint) Unnest module and class names in Ruby tasks
  • Loading branch information
mhashizume authored Dec 7, 2023
2 parents f6ca685 + 6c54cc4 commit 9ef1be2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Enabled: false
RSpec/SubjectStub:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Gemfile:
optional:
":development":
Expand Down
105 changes: 54 additions & 51 deletions files/rb_task_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9ef1be2

Please sign in to comment.