Include Calculations module instead of prepending #928
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another gem (groupdate: https://github.com/ankane/groupdate by @ankane) also patches the
ActiveRecord::Relation#calculate
method and breaks when used with this library. Prepending thisCalculations
module prevents any other libraries from patching this method, and it looks like aninclude
will have the same desired effect to patch existing out-of-the-box ActiveRecord code. I'm not sure if this is prepended to ensure nothing else is patching#calculate
, and how important that may be.I see the reasoning for patching
#calculate
by this library is helpfully defined in the patched method:# Same as original except we don't perform PostgreSQL hack that removes ordering.
Comparing to the original activerecord
#calculate
implementation, the following lines are removed forcount
operations:In my somewhat obscure edge case scenario where both of these gems are used (along with postgres and sqlserver), I need to choose which gem is going to win the monkey patching war for
#calculate
. Changing this fromprepend
toinclude
allows me to make this choice by the sequence the gems are loaded in. The downside of this change is it could allow another gem to patch#calculate
away from the intended version in this library (but hopefully that is not much of a threat, and maybe a feature, as it is in my case).