Also improve the testability of the injection code by allowing dependency-injection of the Warning constant so we can inject a different module under test.
We still need to function on Ruby 1.9, so will have to maintain a split in injection based on ruby version.
What?
Warning
usingModule#prepend
rather thanModule#extend
on modern rubiesalias_method
/Module#extend
on old rubiesWhy?
Modern[^1] rubies allow more modern methods of patching to play nicely with other gems that may also patch the same behaviour. https://blog.appsignal.com/2021/08/24/responsible-monkeypatching-in-ruby.html#monkeypatching-responsibly has a bunch more context and background around why this is compared to what we used to do.
Also improve the testability of the injection code by allowing dependency-injection of the
Warning
constant so we can inject a different module under test.We still need to function on Ruby 1.9, so will have to maintain a split in injection based on ruby version.
[^1]: Ruby 2.0 and higher