From 182a3eb462bdca665c51cb2e5951df857b8853fb Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 27 Nov 2015 23:08:02 -0500 Subject: [PATCH] Extract method: pt_record_object_changes? --- lib/paper_trail/has_paper_trail.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 3d893a93..52f8c577 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -369,7 +369,7 @@ module PaperTrail if respond_to?(:updated_at) data[PaperTrail.timestamp_field] = updated_at end - if paper_trail_options[:save_changes] && changed_notably? && self.class.paper_trail_version_class.column_names.include?('object_changes') + if pt_record_object_changes? && changed_notably? data[:object_changes] = pt_recordable_object_changes end if self.class.paper_trail_version_class.column_names.include?('transaction_id') @@ -391,7 +391,7 @@ module PaperTrail if respond_to?(:updated_at) data[PaperTrail.timestamp_field] = updated_at end - if paper_trail_options[:save_changes] && self.class.paper_trail_version_class.column_names.include?('object_changes') + if pt_record_object_changes? data[:object_changes] = pt_recordable_object_changes end if self.class.paper_trail_version_class.column_names.include?('transaction_id') @@ -403,6 +403,14 @@ module PaperTrail end end + # Returns a boolean indicating whether to store serialized version diffs + # in the `object_changes` column of the version record. + # @api private + def pt_record_object_changes? + paper_trail_options[:save_changes] && + self.class.paper_trail_version_class.column_names.include?('object_changes') + end + # Returns an object which can be assigned to the `object` attribute of a # nascent version record. If the `object` column is a postgres `json` # column, then a hash can be used in the assignment, otherwise the column