Skip to content

Commit ac02bb4

Browse files
committed
Use match? instead of =~ to reduce memory usage
If we don't need the match data then let's not allocate that data. Signed-off-by: Tim Smith <[email protected]>
1 parent 7a0fcf1 commit ac02bb4

File tree

12 files changed

+14
-14
lines changed

12 files changed

+14
-14
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
## [v3.0.0](https://github.com/test-kitchen/kitchen-ec2/tree/v3.0.0) (2019-05-01)
6262
[Full Changelog](https://github.com/test-kitchen/kitchen-ec2/compare/v2.4.0..v3.0.0)
6363

64-
- Switch from the monolithic aws-sdk-v2 to the just aws-sdk-ec2 aka aws-sdk-v3. This greatly reduces the number of dependencies necessary for this plugin, but is a major change that makes it incompatible with older released of Chef-DK that require aws-sdk-v2.
64+
- Switch from the monolithic aws-sdk-v2 to the just aws-sdk-ec2 aka aws-sdk-v3. This greatly reduces the number of dependencies necessary for this plugin, but is a major change that makes it incompatible with older released of ChefDK that require aws-sdk-v2.
6565
- Require Ruby 2.3 or later as Ruby 2.2 is now EOL
6666
- Loosen the dependency on Test Kitchen to allow this plugin to work with Test Kitchen 2.0
6767
- Fix hostname detection to not fail when the system doesn't have a public IP. Thanks [@niekrasp](https://github.com/niekrasp)
@@ -297,7 +297,7 @@
297297

298298
**Closed issues:**
299299

300-
- Requesting to include this plug-in in Chefdk [\#218](https://github.com/test-kitchen/kitchen-ec2/issues/218)
300+
- Requesting to include this plug-in in ChefDK [\#218](https://github.com/test-kitchen/kitchen-ec2/issues/218)
301301
- Can't ssh to instance after it's created [\#217](https://github.com/test-kitchen/kitchen-ec2/issues/217)
302302
- No installation instructions [\#216](https://github.com/test-kitchen/kitchen-ec2/issues/216)
303303
- availability\_zone is always b [\#215](https://github.com/test-kitchen/kitchen-ec2/issues/215)

lib/kitchen/driver/aws/instance_generator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
133133

134134
availability_zone = config[:availability_zone]
135135
if availability_zone
136-
if availability_zone =~ /^[a-z]$/i
136+
if /^[a-z]$/i.match?(availability_zone)
137137
availability_zone = "#{config[:region]}#{availability_zone}"
138138
end
139139
i[:placement] = { availability_zone: availability_zone.downcase }
@@ -176,7 +176,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
176176
end
177177
availability_zone = config[:availability_zone]
178178
if availability_zone
179-
if availability_zone =~ /^[a-z]$/i
179+
if /^[a-z]$/i.match?(availability_zone)
180180
availability_zone = "#{config[:region]}#{availability_zone}"
181181
end
182182
i[:placement] = { availability_zone: availability_zone.downcase }

lib/kitchen/driver/aws/standard_platform/amazon.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def image_search
3939
end
4040

4141
def self.from_image(driver, image)
42-
if image.name =~ /amzn-ami/i
42+
if /amzn-ami/i.match?(image.name)
4343
image.name =~ /\b(\d+(\.\d+[\.\d])?)/i
4444
new(driver, "amazon", (Regexp.last_match || [])[1], image.architecture)
4545
end

lib/kitchen/driver/aws/standard_platform/amazon2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def image_search
3939
end
4040

4141
def self.from_image(driver, image)
42-
if image.name =~ /amzn2-ami/i
42+
if /amzn2-ami/i.match?(image.name)
4343
image.name =~ /\b(\d+(\.\d+[\.\d])?)/i
4444
new(driver, "amazon2", (Regexp.last_match || [])[1], image.architecture)
4545
end

lib/kitchen/driver/aws/standard_platform/centos.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def sort_by_version(images)
7575
end
7676

7777
def self.from_image(driver, image)
78-
if image.name =~ /centos/i
78+
if /centos/i.match?(image.name)
7979
image.name =~ /\b(\d+(\.\d+)?)\b/i
8080
new(driver, "centos", (Regexp.last_match || [])[1], image.architecture)
8181
end

lib/kitchen/driver/aws/standard_platform/debian.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def image_search
6060
end
6161

6262
def self.from_image(driver, image)
63-
if image.name =~ /debian/i
63+
if /debian/i.match?(image.name)
6464
image.name =~ /\b(\d+|#{DEBIAN_CODENAMES.values.join("|")})\b/i
6565
version = (Regexp.last_match || [])[1]
6666
if version && version.to_i == 0

lib/kitchen/driver/aws/standard_platform/fedora.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def image_search
3939
end
4040

4141
def self.from_image(driver, image)
42-
if image.name =~ /fedora/i
42+
if /fedora/i.match?(image.name)
4343
image.name =~ /\b(\d+(\.\d+)?)\b/i
4444
new(driver, "fedora", (Regexp.last_match || [])[1], image.architecture)
4545
end

lib/kitchen/driver/aws/standard_platform/freebsd.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def image_search
4141
end
4242

4343
def self.from_image(driver, image)
44-
if image.name =~ /freebsd/i
44+
if /freebsd/i.match?(image.name)
4545
image.name =~ /\b(\d+(\.\d+)?)\b/i
4646
new(driver, "freebsd", (Regexp.last_match || [])[1], image.architecture)
4747
end

lib/kitchen/driver/aws/standard_platform/rhel.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def image_search
4545
end
4646

4747
def self.from_image(driver, image)
48-
if image.name =~ /rhel/i
48+
if /rhel/i.match?(image.name)
4949
image.name =~ /\b(\d+(\.\d+)?)/i
5050
new(driver, "rhel", (Regexp.last_match || [])[1], image.architecture)
5151
end

lib/kitchen/driver/aws/standard_platform/ubuntu.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def image_search
3939
end
4040

4141
def self.from_image(driver, image)
42-
if image.name =~ /ubuntu/i
42+
if /ubuntu/i.match?(image.name)
4343
image.name =~ /\b(\d+(\.\d+)?)\b/i
4444
new(driver, "ubuntu", (Regexp.last_match || [])[1], image.architecture)
4545
end

lib/kitchen/driver/aws/standard_platform/windows.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def sort_by_version(images)
7070
end
7171

7272
def self.from_image(driver, image)
73-
if image.name =~ /Windows/i
73+
if /Windows/i.match?(image.name)
7474
# 2008 R2 SP2
7575
if image.name =~ /(\b\d+)\W*(r\d+)?/i
7676
major, revision = (Regexp.last_match || [])[1], (Regexp.last_match || [])[2]

lib/kitchen/driver/ec2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def create(state)
261261

262262
info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).")
263263
instance.transport.connection(state).wait_until_ready
264-
create_ec2_json(state) if instance.provisioner.name =~ /chef/i
264+
create_ec2_json(state) if /chef/i.match?(instance.provisioner.name)
265265
debug("ec2:create '#{state[:hostname]}'")
266266
rescue Exception
267267
# Clean up any auto-created security groups or keys on the way out.

0 commit comments

Comments
 (0)