Skip to content

Commit 9ef1be2

Browse files
authored
Merge pull request #687 from MartyEwings/main
(maint) Unnest module and class names in Ruby tasks
2 parents f6ca685 + 6c54cc4 commit 9ef1be2

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

.rubocop.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ Style/BlockDelimiters:
3737
be consistent then.
3838
EnforcedStyle: braces_for_chaining
3939
Style/ClassAndModuleChildren:
40-
Description: Compact style reduces the required amount of indentation.
41-
EnforcedStyle: compact
40+
Enabled: false
4241
Style/EmptyElse:
4342
Description: Enforce against empty else clauses, but allow `nil` for clarity.
4443
EnforcedStyle: empty

.sync.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Enabled: false
88
RSpec/SubjectStub:
99
Enabled: false
10+
Style/ClassAndModuleChildren:
11+
Enabled: false
1012
Gemfile:
1113
optional:
1214
":development":

files/rb_task_helper.rb

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
# frozen_string_literal: true
22

33
# Puppet Agent task helper
4-
module PuppetAgent::RbTaskHelper
5-
private
6-
7-
def error_result(error_type, error_message)
8-
{
9-
'_error' => {
10-
'msg' => error_message,
11-
'kind' => error_type,
12-
'details' => {},
13-
},
14-
}
15-
end
16-
17-
def puppet_bin_present?
18-
File.exist?(puppet_bin)
19-
end
20-
21-
# Returns the path to the Puppet agent executable
22-
def puppet_bin
23-
@puppet_bin ||= if Puppet.features.microsoft_windows?
24-
puppet_bin_windows
25-
else
26-
'/opt/puppetlabs/bin/puppet'
27-
end
28-
end
29-
30-
# Returns the path to the Puppet agent executable on Windows
31-
def puppet_bin_windows
32-
require 'win32/registry'
33-
34-
install_dir = begin
35-
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
36-
# Rescue missing key
37-
dir = begin
38-
reg['RememberedInstallDir64']
39-
rescue StandardError
40-
''
41-
end
42-
# Both keys may exist, make sure the dir exists
43-
break dir if File.exist?(dir)
44-
45-
# Rescue missing key
46-
begin
47-
reg['RememberedInstallDir']
48-
rescue StandardError
49-
''
4+
module PuppetAgent
5+
# Puppet Agent Ruby task helper
6+
module RbTaskHelper
7+
private
8+
9+
def error_result(error_type, error_message)
10+
{
11+
'_error' => {
12+
'msg' => error_message,
13+
'kind' => error_type,
14+
'details' => {},
15+
},
16+
}
17+
end
18+
19+
def puppet_bin_present?
20+
File.exist?(puppet_bin)
21+
end
22+
23+
# Returns the path to the Puppet agent executable
24+
def puppet_bin
25+
@puppet_bin ||= if Puppet.features.microsoft_windows?
26+
puppet_bin_windows
27+
else
28+
'/opt/puppetlabs/bin/puppet'
29+
end
30+
end
31+
32+
# Returns the path to the Puppet agent executable on Windows
33+
def puppet_bin_windows
34+
require 'win32/registry'
35+
36+
install_dir = begin
37+
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
38+
# Rescue missing key
39+
dir = begin
40+
reg['RememberedInstallDir64']
41+
rescue StandardError
42+
''
43+
end
44+
# Both keys may exist, make sure the dir exists
45+
break dir if File.exist?(dir)
46+
47+
# Rescue missing key
48+
begin
49+
reg['RememberedInstallDir']
50+
rescue StandardError
51+
''
52+
end
5053
end
54+
rescue Win32::Registry::Error
55+
# Rescue missing registry path
56+
''
5157
end
52-
rescue Win32::Registry::Error
53-
# Rescue missing registry path
54-
''
55-
end
5658

57-
File.join(install_dir, 'bin', 'puppet.bat')
59+
File.join(install_dir, 'bin', 'puppet.bat')
60+
end
5861
end
5962
end

0 commit comments

Comments
 (0)