Skip to content

Commit

Permalink
Style/RedundantBegin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbeck committed Aug 30, 2021
1 parent 860004f commit 43ee89f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,3 @@ Security/YAMLLoad:
- 'spec/paper_trail/events/destroy_spec.rb'
- 'spec/paper_trail/model_spec.rb'
- 'spec/paper_trail/serializer_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/paper_trail/events/base.rb'
24 changes: 14 additions & 10 deletions lib/paper_trail/events/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,11 @@ def changed_in_latest_version
@changed_in_latest_version ||= changes_in_latest_version.keys
end

# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
# https://github.com/paper-trail-gem/paper_trail/pull/899
# Memoized to reduce memory usage
#
# @api private
def changes_in_latest_version
# Memoized to reduce memory usage
@changes_in_latest_version ||= begin
if @in_after_callback
@record.saved_changes
else
@record.changes
end
end
@changes_in_latest_version ||= load_changes_in_latest_version
end

# An attributed is "ignored" if it is listed in the `:ignore` option
Expand All @@ -134,6 +126,18 @@ def ignored_attr_has_changed?
ignored.any? && (changed_in_latest_version & ignored).any?
end

# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
# https://github.com/paper-trail-gem/paper_trail/pull/899
#
# @api private
def load_changes_in_latest_version
if @in_after_callback
@record.saved_changes
else
@record.changes
end
end

# PT 10 has a new optional column, `item_subtype`
#
# @api private
Expand Down

0 comments on commit 43ee89f

Please sign in to comment.