Skip to content

Commit

Permalink
Optimize our requires
Browse files Browse the repository at this point in the history
Avoid requiring things that are already defined. Rubygems is very slow at traversing the filesystem.

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Aug 20, 2020
1 parent 25d1bbb commit e37ce8d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
desc "Run all quality tasks"
task quality: %i{style stats}

require "yard"
require "yard" unless defined?(YARD)
YARD::Rake::YardocTask.new

task default: %i{test quality style}
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "base64"
require "base64" unless defined?(Base64)
require "aws-sdk-ec2"

module Kitchen
Expand Down
12 changes: 6 additions & 6 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "benchmark"
require "json"
require "benchmark" unless defined?(Benchmark)
require "json" unless defined?(JSON)
require "kitchen"
require_relative "ec2_version"
require_relative "aws/client"
Expand All @@ -34,10 +34,10 @@
require_relative "aws/standard_platform/windows"
require "aws-sdk-ec2"
require "aws-sdk-core/waiters/errors"
require "retryable"
require "time"
require "etc"
require "socket"
require "retryable" unless defined?(Retryable)
require "time" unless defined?(Time)
require "etc" unless defined?(Etc)
require "socket" unless defined?(Socket)

module Kitchen

Expand Down
4 changes: 2 additions & 2 deletions spec/kitchen/driver/aws/instance_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

require "kitchen/driver/aws/instance_generator"
require "kitchen/driver/aws/client"
require "tempfile"
require "base64"
require "tempfile" unless defined?(Tempfile)
require "base64" unless defined?(Base64)
require "aws-sdk-ec2"

describe Kitchen::Driver::Aws::InstanceGenerator do
Expand Down

0 comments on commit e37ce8d

Please # to comment.