-
Notifications
You must be signed in to change notification settings - Fork 899
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
An idea to combat model pollution #719
Conversation
I think I'd prefer record.version.live?
record.version.originator
record.version.source
record.version.switched_on?
record.version.save? |
Cool, I'm glad you like the general idea. I'm not opposed to the word version, but I am concerned it's bit of a common word. Any other ideas? "trail" is uncommon and easy to type. |
You can get the best of both worlds by making it configurable. |
That's true, we could pass the name(s) to |
8b3a04c
to
aa7b634
Compare
@jaredbeck, apologies for the delay in reviewing this. This seems like a sensible refactor to me, since requests tend to come in pretty consistently to rename method names provided to models that are causing namespace collision in ActiveRecord. The questions is does it make sense for all instance methods (and possibly even class methods) provided by PaperTrail to be 'hidden' / 'extracted' behind a barrier such as this. I'm not sure what the answer is, but it might be sensible to hold off on this until PaperTrail 5 if the answer is to indeed extract all of them, since it will cause breakage. Or maybe we do the transition in PaperTrail 4 but have the old methods show a deprecation warning, and then remove the old methods once PaperTrail 5 rolls out. |
That's a good question. PT adds at least 36 instance methods by my count. This PR only extracts one of them. Maybe the next step is to try extracting a dozen of them and see if we're still happy with this idea. I'm happy to move slowly on this, as it would be a big change to the public API and I want to get it right.
This is a big change, and I don't want it to hold up PT 5. I'm happy if this doesn't happen until PT 6. We could do a 5.99 release that deprecates the old polluting API. |
a104b4d
to
e7ce81a
Compare
OK, I've taken this from an idea to a proof of concept. I'd like your feedback again, please, to know if I should continue. Things I like so far:
Things I don't like:
Next StepsSean and Ben, please take another look and let me know your concerns. If we do decide to continue with this, we could then discuss the name of the two important new methods currently named "paper_trail". Thanks for your help! |
2f36905
to
46d9398
Compare
Status: class methods 63% done, instance methods 28% done. Deprecation scheduled for 5.2, removal in 6.0. |
00ee5bd
to
f7e23e4
Compare
9a7c18c
to
c8c1233
Compare
Status: class methods 100% done, instance methods 60% done. |
5859568
to
b6545e9
Compare
Problem ------- `has_paper_trail` adds too many methods to the ActiveRecord model. > If I'm counting correctly, installing the paper_trail gem adds 36 instance > methods and 10 class methods to all of your active record models. Of those > 46, 13 have a prefix, either "pt_" or "paper_trail_". I don't know what the > best way to deal with this is. Ideally, we'd add far fewer methods to > people's models. If we were able to add fewer methods to models, then I > wouldn't mind prefixing all of them. > #703 Solution -------- Add only two methods to the AR model. 1. An instance method `#paper_trail` 2. A class method `.paper_trail` The instance method would return a `RecordTrail` and the class method would return a `ClassTrail`. Those names are totally up for debate. Advantages ---------- - Plain ruby, easy to understand - Adding new methods to e.g. the `RecordTrail` does not add any methods to the AR model. - Methods privacy is more strongly enforced. - Enables isolated testing of e.g. `RecordTrail`; it can be constructed with a mock AR instance. Disadvantages ------------- - Two new classes, though they are simple.
b6545e9
to
ad3806f
Compare
Whew. This is complete, and ready for final review. 7 class methods and 30 instance methods are deprecated, and a handful of private methods are moved without deprecation. Here are the things I'd like feedback on:
Thanks for the review! |
@batter @seanlinsley any feedback? objections? |
@jaredbeck sorry, I'll try responding in the next few days. |
I'm going to go ahead and merge this. I'll wait another week before releasing it (in 5.2.0) to give y'all one more week to raise any objections. After it's released, it will be much harder to change the names of things, especially the critical |
Sean and Ben, I'll be releasing this, as 5.2.0, this weekend, unless I hear any objections. If you want another week to review it before it's released, please let me know, thanks. |
Problem
has_paper_trail
adds too many methods to the ActiveRecord model, as described in #703, and others.Solution
Add only two methods to the AR model.
#paper_trail
.paper_trail
The instance method would return a
RecordTrail
and the class method wouldreturn a
ClassTrail
. Those names are totally up for debate.Advantages
RecordTrail
does not add any methods tothe AR model.
RecordTrail
; it can be constructed with amock AR instance.
Disadvantages