lib/paper_trail/events/base.rb in paper_trail-10.1.0 vs lib/paper_trail/events/base.rb in paper_trail-10.2.0
- old
+ new
@@ -104,44 +104,15 @@
end
skip = @record.paper_trail_options[:skip]
(changed_in_latest_version - ignore) - skip
end
- # Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
- # https://github.com/paper-trail-gem/paper_trail/pull/899
- #
# @api private
def changed_in_latest_version
- if @in_after_callback && RAILS_GTE_5_1
- @record.saved_changes.keys
- else
- @record.changed
- end
+ changes_in_latest_version.keys
end
- # @api private
- def prepare_object_changes(changes)
- changes = serialize_object_changes(changes)
- changes = recordable_object_changes(changes)
- changes
- end
-
- # @api private
- def serialize_object_changes(changes)
- AttributeSerializers::ObjectChangesAttribute.
- new(@record.class).
- serialize(changes)
- changes.to_hash
- end
-
- # @api private
- def notable_changes
- changes_in_latest_version.delete_if { |k, _v|
- !notably_changed.include?(k)
- }
- end
-
# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
# https://github.com/paper-trail-gem/paper_trail/pull/899
#
# @api private
def changes_in_latest_version
@@ -219,10 +190,17 @@
value
end
end
# @api private
+ def notable_changes
+ changes_in_latest_version.delete_if { |k, _v|
+ !notably_changed.include?(k)
+ }
+ end
+
+ # @api private
def notably_changed
only = @record.paper_trail_options[:only].dup
# Remove Hash arguments and then evaluate whether the attributes (the
# keys of the hash) should also get pushed into the collection.
only.delete_if do |obj|
@@ -243,10 +221,17 @@
except(*@record.paper_trail_options[:skip])
AttributeSerializers::ObjectAttribute.new(@record.class).serialize(attrs)
attrs
end
+ # @api private
+ def prepare_object_changes(changes)
+ changes = serialize_object_changes(changes)
+ changes = recordable_object_changes(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,
# otherwise the column is a `text` column, and we must perform the
# serialization here, using `PaperTrail.serializer`.
@@ -290,9 +275,17 @@
if @record.class.paper_trail.version_class.object_col_is_json?
object_attrs_for_paper_trail(is_touch)
else
PaperTrail.serializer.dump(object_attrs_for_paper_trail(is_touch))
end
+ end
+
+ # @api private
+ def serialize_object_changes(changes)
+ AttributeSerializers::ObjectChangesAttribute.
+ new(@record.class).
+ serialize(changes)
+ changes.to_hash
end
end
end
end