Extract method: #load_changeset

This commit is contained in:
Jared Beck 2015-12-07 11:40:51 -05:00
parent 3a72b7f7c7
commit cfab26b64d
1 changed files with 12 additions and 8 deletions

View File

@ -212,14 +212,7 @@ module PaperTrail
# not have an `object_changes` text column.
def changeset
return nil unless self.class.column_names.include? 'object_changes'
_changes = HashWithIndifferentAccess.new(object_changes_deserialized)
@changeset ||= _changes.tap do |changes|
if PaperTrail.serialized_attributes?
item_type.constantize.unserialize_attribute_changes_for_paper_trail!(changes)
end
end
rescue
{}
@changeset ||= load_changeset
end
# Returns who put the item into the state stored in this version.
@ -267,6 +260,17 @@ module PaperTrail
# though private *class* methods are possible.
private
# @api private
def load_changeset
changes = HashWithIndifferentAccess.new(object_changes_deserialized)
if PaperTrail.serialized_attributes?
item_type.constantize.unserialize_attribute_changes_for_paper_trail!(changes)
end
changes
rescue # TODO: Rescue something specific
{}
end
# @api private
def object_changes_deserialized
if self.class.object_changes_col_is_json?