-
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
add 'limit' option to has_paper_trail to override global PaperTrail.config.version_limit setting #1194
Conversation
has_paper_trail limit: 2 Hi Enrico, I like this proposed API. I feel like this idea has been discussed in the past, but don't have time to go looking for it right now. |
Jared, didn't know about the closed pr #915 .
Looks like the solution could be to use item_subtype, but I read in the documents that it's supposed to be optional in the migrations... (yet the tests rely on it, since it's part of the dummy app). I made some changes to make it work using the item_subtype attribute (by using constantize and and avoiding instantiating item). All tests work (including the one I had to change the code with .reify(dup: true) def version_limit_for_item
klass = (respond_to?(:item_subtype) && item_subtype ? item_subtype : item_type).constantize
if klass.respond_to?(:paper_trail_options) && klass.paper_trail_options.key?(:limit)
return klass.paper_trail_options[:limit]
end
PaperTrail.config.version_limit
end |
Jared, so my conclusion is that this feature (per-class limit in the has_paper_trail block) works correctly for non-STI classes but fails with STI classes when the The code as of now uses Questions:
Thanks! |
Hi Enrico, I haven't had time to review this PR (I haven't even read all the comments) but I'll try to quickly answer your latest questions.
It was determined that most people do not need
Yes, in section 4.b.1 please.
In theory, errors like this can be very helpful (better than docs) and I'd encourage you to add one. In practice they can be hard to implement because it can't be checked until we're certain that ActiveRecord will have loaded the schema. Generally speaking, the later you perform the check, the better. |
…PaperTrail.config.version_limit value on a per-model basis. This feature requires the item_subtype column in the versions table.
I think I'm done. please check when you get a chance. |
Hi Enrico, I've done my first review. I've pushed my suggestions. Please review them. Summary:
|
[ci skip]
lib/paper_trail/version_concern.rb
Outdated
# | ||
# TODO: Duplication: similar `constantize` in Reifier#version_reification_class | ||
def version_limit | ||
if PaperTrail::Version.column_names.include?("item_subtype") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if PaperTrail::Version.column_names.include?("item_subtype") | |
if self.class.item_subtype_column_present? |
I think this is a must, now that you've added the class method to check for the item_subtype...
Jared, your proposed changes look a lot cleaner than what I came up with (and I have to embarrassedly admit that in this process I learned about Please let me know about my suggestion above. If you agree, I can make the change and squish all commits. |
Thanks! 😊
Did you know that Matz calls it the "lonely operator" because it looks like a person sitting and looking at a stone? 😀
Good catch, patched by 81f760b
You don't have to, I can squash when I merge this PR. You'll still be the author of the resulting commit. I'm just waiting for CI to pass. |
…onfig.version_limit setting (paper-trail-gem#1194) * add 'limit' option to has_paper_trail allowing users to override the PaperTrail.config.version_limit value on a per-model basis. This feature requires the item_subtype column in the versions table. * Suggestions to be squashed into PR 1194 * Squash: trim trailing whitespace [ci skip] * Squash: use item_subtype_column_present?
v10.3.1 * tag 'v10.3.1': (72 commits) Release 10.3.1 Allow incompatible versions of ActiveRecord Temporarily constrain rails 6 to < rc2 Temporarily allow mysql builds to fail refactor: remove unused generator Docs: object_changes_adapter Updating new links (paper-trail-gem#1207) rubocop 0.71.0 (was 0.62.0) Update readme for generator error Faster way to update from YAML to JSON. activerecord 6.0.0.rc1 requires sqlite3 ~> 1.4 update migration to jsonb with object_changes add guidance for users who are trying to solve their issues Docs: release instructions Release 10.3.0 Release 10.3.0 Fixes item_id For Versions Migration add 'limit' option to has_paper_trail to override global PaperTrail.config.version_limit setting (paper-trail-gem#1194) Docs: temporarily not accepting issues add quotes to SQL date in README ...
…PaperTrail.config.version_limit value on a per-model basis.
Thank you for your contribution!
Check the following boxes:
master
(if not - rebase it).code introduces user-observable changes.
and description in grammatically correct, complete sentences.