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

Extract class: Reifier #583

Merged
merged 1 commit into from
Sep 28, 2015
Merged

Extract class: Reifier #583

merged 1 commit into from
Sep 28, 2015

Conversation

jaredbeck
Copy link
Member

This refactoring encapsulates the process of reification, separating
it from the model (VersionConcern).

The ABC complexity score of VersionConcern (measured by flog) is
reduced from 750 to 362, a 52% reduction.

Finally, this refactoring provides a truely private namespace for
methods like reify_has_many_through. Such methods will no
longer be mixed into PaperTrail::Version, or end-user's version
models, if any.

@jaredbeck jaredbeck added this to the 4.1.0 milestone Aug 3, 2015
@jaredbeck jaredbeck mentioned this pull request Aug 3, 2015
@jaredbeck
Copy link
Member Author

Just for fun (it doesn't tell us anything flog can't), here is the Code Climate analysis of this refactoring (attached):

screen shot 2015-08-03 at 7 22 14 pm

@batter
Copy link
Collaborator

batter commented Aug 4, 2015

Yea, I will agree that the code base as a whole could definitely stand some refactoring into smaller modules and methods of less length, I've certainly allowed some of the methods to become unwieldy over time (not that I can remember it ever being super great in that regard).

Do you think it makes more sense to have this Reifier be a class or a mixin module? Any particular reasons why or why not? And could we potentially memoize the Reifier instance(s) when they are generated if we are going to stick with the class?

@jaredbeck
Copy link
Member Author

Do you think it makes more sense to have this Reifier be a class or a mixin module? Any particular reasons why or why not?

I'd prefer to not mix Reifier into VersionConcern. By not mixing in, we reduce our public API.

.. this refactoring provides a truly private namespace for
methods like reify_has_many_through. Such methods will no
longer be mixed into PaperTrail::Version, or end-user's version
models, if any.

Also, I think this class is easier to understand if it stands alone. It's still tightly coupled to ActiveRecord (a lot of AR methods are called) but they are all called with explicit receiver, so the coupling is more obvious.

And could we potentially memoize the Reifier instance(s) when they are generated if we are going to stick with the class?

I don't think so, not the way it's currently written. Are you concerned about memory usage? I could do some profiling fairly easily.

@jaredbeck
Copy link
Member Author

Mind if I merge this, Ben?

@batter
Copy link
Collaborator

batter commented Aug 11, 2015

Apologies for the delayed review, I've been on vacation. I'll take a closer look this afternoon.

module PaperTrail

# Given a version record and some options, builds a new model object.
# @api private
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this comment mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

@api private indicates a private part of a library's API.

I've seen it, and its inverse @api public, used in major ruby libraries like rspec (https://github.com/rspec/rspec-expectations/blob/14faeab88f319ac0c2e4d793ec02c2b69eb52a5c/lib/rspec/matchers/composable.rb#L9). I think it comes from javadoc originally.

@jaredbeck
Copy link
Member Author

Sorry I've been slow on reviewing this, just started a new job, I'll try to go through it more thoroughly in the next few days, looks good on the surface.

Thanks. Don't rush your review (it's a big change!) but there is going to be a conflict with #596 so it would be great if I didn't have to rebase this too many times. Git conflicts aren't a big deal, but let's not let this get stale if it is something you're interested in. Thanks.

@jaredbeck jaredbeck force-pushed the extract_reify branch 3 times, most recently from d729b29 to 7377b6d Compare September 19, 2015 16:46
@jaredbeck
Copy link
Member Author

Ben, this is ready for another review. I've changed it from a class to a module as we discussed and I've rebased, resolving the conflict with #596

This refactoring encapsulates the process of reification, separating
it from the model (VersionConcern).

The ABC complexity score of VersionConcern (measured by flog) is
reduced from 750 to 362, a 52% reduction.

Finally, this refactoring provides a truely private namespace for
methods like `reify_has_many_through`. Such methods will no
longer be mixed into PaperTrail::Version, or end-user's version
models, if any.
@jaredbeck
Copy link
Member Author

Mind if I merge this? I'm getting a little antsy because I had to fix another conflict today, sorry.

@batter
Copy link
Collaborator

batter commented Sep 28, 2015

Sorry Jared, was away on a trip with limited access to internet for the last 5 days. This looks good to me, and it is aligned with what we discussed during our conversation. 👍

batter added a commit that referenced this pull request Sep 28, 2015
Extract functionality to module: Reifier
@batter batter merged commit f64c4f3 into master Sep 28, 2015
@jaredbeck jaredbeck deleted the extract_reify branch September 30, 2015 21:52
@jaredbeck
Copy link
Member Author

Sorry Jared, was away on a trip with limited access to internet for the last 5 days.

No worries, thanks for the review, I know it was a big one!

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.

2 participants