Skip to content

Commit 430a252

Browse files
committed
(puppetlabs#301) Make code work in Ruby 2.3.0
In 08936f9 ("(MAINT) Rubocop: Fix Performance/RegexpMatch"), a few Regexp matches were switched from `=~` to `.match?`. Unfortuantely, `.match?` [wasn’t introduced until Ruby 2.4.6][match?], so that broke Ruby 2.3.0 compatibility. This reverts that commit and disables the relevant rubocop check. [match?]: https://apidock.com/ruby/String/match%3F
1 parent 53fd169 commit 430a252

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

.rubocop.yml

+4
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,7 @@ Style/HashTransformValues:
599599
Naming/MethodParameterName:
600600
Enabled: true
601601
AllowedNames: [ o ]
602+
603+
# match? was added in Ruby 2.4.6
604+
Performance/RegexpMatch:
605+
Enabled: false

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PuppetLint.configuration.ignore_paths = %w(acceptance/**/*.pp spec/**/*.pp pkg/*
5656
desc 'Validate Ruby source files and ERB templates.'
5757
task :validate do
5858
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
59-
sh "ruby -c #{ruby_file}" unless /spec\/fixtures/.match?(ruby_file)
59+
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
6060
end
6161
Dir['lib/puppet-strings/yard/templates/**/*.erb'].each do |template|
6262
sh "erb -P -x -T '-' #{template} | ruby -c"

lib/puppet-strings/markdown/function.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def render
2121

2222
def type
2323
t = @registry[:type]
24-
if /ruby4x/.match?(t)
24+
if t =~ /ruby4x/
2525
"Ruby 4.x API"
26-
elsif /ruby3/.match?(t)
26+
elsif t =~ /ruby3/
2727
"Ruby 3.x API"
28-
elsif /ruby/.match?(t)
28+
elsif t =~ /ruby/
2929
"Ruby"
3030
else
3131
"Puppet Language"

lib/puppet/face/strings.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
def check_required_features
149149
raise RuntimeError, "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard?
150150
raise RuntimeError, "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen?
151-
raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(/^1\.8/)
151+
raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION =~ /^1\.8/
152152
end
153153

154154
# Builds the options to PuppetStrings.generate.

0 commit comments

Comments
 (0)