Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize our requires #60

Merged
merged 3 commits into from
Aug 21, 2020
Merged

Optimize our requires #60

merged 3 commits into from
Aug 21, 2020

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Aug 21, 2020

Avoid requiring things that are already defined. Rubygems is very slow at traversing the filesystem.

Signed-off-by: Tim Smith [email protected]

Avoid requiring things that are already defined. Rubygems is very slow at traversing the filesystem.

Signed-off-by: Tim Smith <[email protected]>
@tas50 tas50 requested review from a team as code owners August 21, 2020 18:08
Signed-off-by: Tim Smith <[email protected]>
@@ -16,7 +16,7 @@
# limitations under the License.
#

require "time"
require "time" unless defined?(Time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is probably not a good candidate for optimizing this way:

irb(main):001:0> defined?(Time)
=> "constant"
irb(main):002:0> Time.new
=> 2020-08-21 11:28:12 -0700
irb(main):003:0> Time.new.iso8601
Traceback (most recent call last):
        4: from /Users/pete/.asdf/installs/ruby/2.6.6/bin/irb:23:in `<main>'
        3: from /Users/pete/.asdf/installs/ruby/2.6.6/bin/irb:23:in `load'
        2: from /Users/pete/.asdf/installs/ruby/2.6.6/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        1: from (irb):3
NoMethodError (undefined method `iso8601' for 2020-08-21 11:28:19 -0700:Time)
irb(main):004:0> require 'time'
=> true
irb(main):005:0> Time.new.iso8601
=> "2020-08-21T11:28:24-07:00"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was just looking at that one. That's not gonna work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated Chefstyle and this PR to check for a specific method

@tas50 tas50 merged commit ad6f224 into master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants