Skip to content

Mongoid criteria refactor #20

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

Merged
merged 19 commits into from
Mar 14, 2018
Merged

Mongoid criteria refactor #20

merged 19 commits into from
Mar 14, 2018

Conversation

asgerb
Copy link
Collaborator

@asgerb asgerb commented Mar 13, 2018

A proposal for a refactor of the mongoid criteria.

I’ve moved it from Mongoid::Criterion::Scrollable to Mongoid::Criteria::Scrollable since Criterion was removed in version 4 of mongoid.

I’ve changed the criteria = self to criteria = dup. This allowed me to use bang methods, which provided a benefit when setting the default sort option.

Otherwise I haven’t changed anything substantial about the code, but have tried to make it more readable. This means I’ve moved the named variables to method calls. I guess one downside of this is performance?

Perhaps some of the decisions are going a bit too far, looking forward to your thoughts!

I’ve also added a spec which checks that the base criteria does not change, but have kept the cursor_criteria = criteria.dup from the original code. While I don’t think the dup was needed before, it is needed now, since the named variables have been removed.

@mongoid-bot
Copy link

mongoid-bot commented Mar 13, 2018

1 Warning
⚠️ Unless you’re refactoring existing code, please update CHANGELOG.md.

Here's an example of a CHANGELOG.md entry:

* [#20](https://github.com/mongoid/mongoid-scroll/pull/20): Mongoid criteria refactor - [@asgerb](https://github.com/asgerb).

Generated by 🚫 danger

Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

This looks great. I'm going to merge, see suggestions for more/future changes.


private

def raise_multiple_sort_fields_error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be a bang method I think, so raise_multiple_sort_fields_error!, for clarity that it fails loudly.

options.sort && options.sort.keys.size != 1
end

def no_sort_option?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe flip it to sort_option??

field.foreign_key? && field.object_id_field? ? bson_type : field.type
end

def bson_type
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should add this to mongoid-compatibility, maybe Mongoid::Compatibility::ObjectId#bson_type. Obviously fine for now here.

@dblock dblock merged commit 413c592 into mongoid:master Mar 14, 2018
@dblock
Copy link
Collaborator

dblock commented Mar 14, 2018

@asgerb Are you interested in joining the maintainers group? Maybe make the next release? (what's your rubygems email/name if so).

@asgerb
Copy link
Collaborator Author

asgerb commented Mar 14, 2018

Hey @dblock, thanks for the quick merge, happy that this was useful 🙂
I'll take a look at your proposals and make another PR.
About joining as a maintainer, I'm afraid I have zero experience as a maintainer, so I'm not sure I'm the best fit? 😉 I don't even have a rubygems login, and never released a gem heh.

@asgerb asgerb deleted the mongoid-criteria-refactor branch March 14, 2018 20:34
@dblock
Copy link
Collaborator

dblock commented Mar 15, 2018

I think you'll do fine @asgerb so this could be your first! You seem to know what you're doing otherwise :) Get a Rubygems login and let me know. I can help you avoid doing anything stupid and we have instructions for things like releasing. Otherwise it's just reviewing other people's PRs and helping in any way you can.

@asgerb
Copy link
Collaborator Author

asgerb commented Mar 16, 2018

Sounds good, I'm up for it 🙂 I'll sign up on rubygems then!

@asgerb
Copy link
Collaborator Author

asgerb commented Mar 19, 2018

OK I'm on Rubygems with a@asgerbehnckejacobsen.dk 🙂

@dblock
Copy link
Collaborator

dblock commented Mar 19, 2018

All added @asgerb. Welcome!

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.

None yet

3 participants