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

Small refactor of relations. #216

Merged
merged 1 commit into from
Jan 17, 2018
Merged

Conversation

dblock
Copy link
Collaborator

@dblock dblock commented Jan 16, 2018

Taking some of the working parts out of #215.

Extracts increment_current_version.

Simplifies fetching of the relation's class or type of relationship by always looking at reflect_on_association and memoizing the result.

Collapses embeds_many_class and embeds_one_class into relation_class_of.

Renames methods from embedded to related so we can continue extending into many-to-many and such.

@dblock dblock force-pushed the refactor-relations branch from cf25e06 to 5308b65 Compare January 16, 2018 20:37
Copy link
Collaborator

@mikwat mikwat left a comment

Choose a reason for hiding this comment

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

Nice refactor.

# @return [ nil | Constant ] Type of relation.
def relation_of(field)
meta = meta_of(field)
meta ? meta.relation : nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we have a dependency on activesupport, would it be safe to use meta.try(:relation) here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would, but it would hide any exception such as the method .relation no longer exists.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point. Too bad we can't rely on Ruby 2.3 safe navigation operator &. yet.

@mongoid-bot
Copy link

mongoid-bot commented Jan 17, 2018

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

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

* [#216](https://github.com/mongoid/mongoid-history/pull/216): Small refactor of relations - [@dblock](https://github.com/dblock).

Generated by 🚫 danger

@coveralls
Copy link

coveralls commented Jan 17, 2018

Coverage Status

Changes Unknown when pulling 5308b65 on dblock:refactor-relations into ** on mongoid:master**.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5308b65 on dblock:refactor-relations into ** on mongoid:master**.

@dblock dblock merged commit af17cfe into mongoid:master Jan 17, 2018
@dblock dblock deleted the refactor-relations branch January 18, 2018 01:14
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.

4 participants