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

Clean up singleton class eval statements #1529

Merged
merged 3 commits into from
Jun 1, 2021
Merged

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented May 27, 2021

Quite a few of our class_eval and class_eval + class << self statements were due to not having access the previously private #prepend or #include methods.

This PR cleans up such usages.

Not all occurrences across the code base were converted, as some performed other operations (e.g. defining methods inside the class << self block). This PR touches the ones that are safe to do so, with minimal refactor.

Ruby 2.0 deprecation checklist

  • Remove 2.0 from CI
  • Remove 2.0-specific code paths
  • Update to 2.1+ standards: https://github.com/ruby/ruby/blob/v2_1_0/NEWS
    • Module#include and Module#prepend are now public methods.
    • Exception#cause (no changes)
    • Array#to_h converts an array of key-value pairs into a Hash.
    • Kernel#singleton_method (no changes)
    • Process.clock_gettime
    • Enumerable#to_h converts a list of key-value pairs into a Hash.
    • instance_eval/class_eval for accessing #include/#prepend
    • Now the default values of keyword arguments can be omitted. Those “required keyword arguments” need giving explicitly at the call time.
  • Update documentation

@marcotc marcotc added the deprecation Involves a deprecation label May 27, 2021
@marcotc marcotc requested a review from a team May 27, 2021 22:49
@marcotc marcotc self-assigned this May 27, 2021
@ericmustin
Copy link
Contributor

It looks like there's some issues with either the exception_handler changes itself for sucker punch, or the way we test exceptions

@marcotc
Copy link
Member Author

marcotc commented May 31, 2021

I fixed the sucker_punch failures.

@codecov-commenter
Copy link

Codecov Report

Merging #1529 (33825ca) into master (b05fddf) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1529   +/-   ##
=======================================
  Coverage   98.23%   98.24%           
=======================================
  Files         877      877           
  Lines       42261    42253    -8     
=======================================
- Hits        41517    41512    -5     
+ Misses        744      741    -3     
Impacted Files Coverage Δ
lib/ddtrace/contrib/active_support/cache/redis.rb 100.00% <100.00%> (ø)
lib/ddtrace/contrib/qless/patcher.rb 94.11% <100.00%> (-0.33%) ⬇️
.../ddtrace/contrib/sucker_punch/exception_handler.rb 100.00% <100.00%> (ø)
lib/ddtrace/opentracer.rb 100.00% <100.00%> (ø)
lib/ddtrace/profiling/ext/forking.rb 100.00% <100.00%> (ø)
spec/ddtrace/contrib/rails/support/rails3.rb 94.11% <100.00%> (-0.07%) ⬇️
spec/ddtrace/profiling/ext/forking_spec.rb 100.00% <100.00%> (+1.86%) ⬆️
spec/support/synchronization_helpers.rb 83.33% <100.00%> (-0.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b05fddf...33825ca. Read the comment docs.

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

end
Rails::Application.singleton_class.class_eval do
def inherited(base)
# raise "You cannot have more than one Rails::Application" if Rails.application
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this change, but this commented out line is a bit suspect 🤔 .

Copy link
Member Author

Choose a reason for hiding this comment

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

ducks

Copy link
Contributor

@ericmustin ericmustin left a comment

Choose a reason for hiding this comment

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

🚀 , 👋 2.0️⃣

@marcotc marcotc merged commit 6c2008a into master Jun 1, 2021
@marcotc marcotc deleted the deprecate-ruby-2.0-eval branch June 1, 2021 18:56
@github-actions github-actions bot added this to the 0.50.0 milestone Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation Involves a deprecation
Projects
Active work
  
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

4 participants