Skip to content

Commit 1d34131

Browse files
ColinHeberttruthbk
authored andcommitted
Avoid proliferation of constants and ensure they're initialised (DataDog#443)
1 parent d55b490 commit 1d34131

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/puppet/reports/datadog_reports.rb

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
API_KEY = config[:datadog_api_key]
1616

1717
# if need be initialize the regex
18-
HOSTNAME_REGEX = config[:hostname_extraction_regex]
19-
begin
20-
HOSTNAME_EXTRACTION_REGEX = Regexp.new HOSTNAME_REGEX unless HOSTNAME_REGEX.nil?
21-
rescue
22-
raise(Puppet::ParseError, "Invalid hostname_extraction_regex #{HOSTNAME_REGEX}")
18+
if !config[:hostname_extraction_regex].nil?
19+
begin
20+
HOSTNAME_EXTRACTION_REGEX = Regexp.new config[:hostname_extraction_regex]
21+
rescue
22+
raise(Puppet::ParseError, "Invalid hostname_extraction_regex #{HOSTNAME_REGEX}")
23+
end
24+
else
25+
HOSTNAME_EXTRACTION_REGEX = nil
2326
end
2427

2528
desc <<-DESC

0 commit comments

Comments
 (0)