lib/paper_trail/events/base.rb in paper_trail-10.3.1 vs lib/paper_trail/events/base.rb in paper_trail-11.0.0
- old
+ new
@@ -71,18 +71,18 @@
end
end
# Rails 5.1 changed the API of `ActiveRecord::Dirty`.
# @api private
- def cache_changed_attributes
+ def cache_changed_attributes(&block)
if RAILS_GTE_5_1
# Everything works fine as it is
yield
else
# Any particular call to `changed_attributes` produces the huge memory allocation.
# Lets use the generic AR workaround for that.
- @record.send(:cache_changed_attributes) { yield }
+ @record.send(:cache_changed_attributes, &block)
end
end
# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
# https://github.com/paper-trail-gem/paper_trail/pull/899
@@ -105,22 +105,26 @@
@record.attribute_was(attr_name.to_s)
end
end
# @api private
- def changed_and_not_ignored
+ def calculated_ignored_array
ignore = @record.paper_trail_options[:ignore].dup
# Remove Hash arguments and then evaluate whether the attributes (the
# keys of the hash) should also get pushed into the collection.
ignore.delete_if do |obj|
obj.is_a?(Hash) &&
obj.each { |attr, condition|
ignore << attr if condition.respond_to?(:call) && condition.call(@record)
}
end
+ end
+
+ # @api private
+ def changed_and_not_ignored
skip = @record.paper_trail_options[:skip]
- (changed_in_latest_version - ignore) - skip
+ (changed_in_latest_version - calculated_ignored_array) - skip
end
# @api private
def changed_in_latest_version
# Memoized to reduce memory usage
@@ -146,11 +150,11 @@
# and/or the `:skip` option. Returns true if an ignored attribute has
# changed.
#
# @api private
def ignored_attr_has_changed?
- ignored = @record.paper_trail_options[:ignore] + @record.paper_trail_options[:skip]
+ ignored = calculated_ignored_array + @record.paper_trail_options[:skip]
ignored.any? && (changed_in_latest_version & ignored).any?
end
# PT 10 has a new optional column, `item_subtype`
#
@@ -245,11 +249,10 @@
end
# @api private
def prepare_object_changes(changes)
changes = serialize_object_changes(changes)
- changes = recordable_object_changes(changes)
- changes
+ recordable_object_changes(changes)
end
# Returns an object which can be assigned to the `object_changes`
# attribute of a nascent version record. If the `object_changes` column is
# a postgres `json` column, then a hash can be used in the assignment,