Style/RedundantBegin

This commit is contained in:
Jared Beck 2021-08-29 23:24:08 -04:00
parent 860004f11d
commit 43ee89fe0d
2 changed files with 14 additions and 16 deletions

View File

@ -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'

View File

@ -109,19 +109,11 @@ module PaperTrail
@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
@ -134,6 +126,18 @@ module PaperTrail
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