-
Notifications
You must be signed in to change notification settings - Fork 898
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
No need to calculate previous values of skipped attributes #1184
Conversation
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.
Hi Rumble, thanks for the contribution. It looks like a good start.
Please add at least one test in spec/paper_trail/events
. You may want to use spec/dummy_app/app/models/skipper.rb
. Feel free to add your fail
to that class.
Please add some comments, at least in events/base.rb
, explaining the importance of avoiding calling skipped attributes.
Thanks!
lib/paper_trail/events/base.rb
Outdated
@@ -59,8 +59,11 @@ def attribute_changed_in_latest_version?(attr_name) | |||
end | |||
|
|||
# @api private | |||
def attributes_before_change(is_touch) | |||
Hash[@record.attributes.map do |k, v| | |||
def attributes_before_change(is_touch, skip: []) |
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.
I don't understand the purpose of the skip
argument. This method is only called from one place, and we always want to skip, so what about renaming this method to nonskipped_attributes_before_change
, and having it always respect skip
?
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.
I was no sure if it is ok to change the behavior of attributes_before_change
method or not, so I added an extra argument to control it.
Renaming this method sounds to be a good idea, too. 👍
Thanks, Rumble. |
I'm going to remove a column of one model. I want to make sure that no one calls it anymore before removing it, so I overwritted it as below:
But
paper_trail
will call it even the attribute is skipped.It calculates all attributes and then filters out skipped attributes.
paper_trail/lib/paper_trail/events/base.rb
Lines 219 to 221 in 85884ba
The flow can be improved to calculate only non-skipped attributes.
master
(if not - rebase it).code introduces user-observable changes.
and description in grammatically correct, complete sentences.