Skip to content

Commit

Permalink
The serialization methods mutate the args they receive so they should…
Browse files Browse the repository at this point in the history
… be bang methods
  • Loading branch information
batter committed May 8, 2015
1 parent 597cb8b commit 158f260
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def paper_trail_version_class
end

# Used for Version#object attribute
def serialize_attributes_for_paper_trail(attributes)
def serialize_attributes_for_paper_trail!(attributes)
# don't serialize before values before inserting into columns of type `JSON` on `PostgreSQL` databases
return attributes if self.paper_trail_version_class.object_col_is_json?

Expand All @@ -132,7 +132,7 @@ def serialize_attributes_for_paper_trail(attributes)
end
end

def unserialize_attributes_for_paper_trail(attributes)
def unserialize_attributes_for_paper_trail!(attributes)
# don't serialize before values before inserting into columns of type `JSON` on `PostgreSQL` databases
return attributes if self.paper_trail_version_class.object_col_is_json?

Expand All @@ -145,7 +145,7 @@ def unserialize_attributes_for_paper_trail(attributes)
end

# Used for Version#object_changes attribute
def serialize_attribute_changes(changes)
def serialize_attribute_changes_for_paper_trail!(changes)
# don't serialize before values before inserting into columns of type `JSON` on `PostgreSQL` databases
return changes if self.paper_trail_version_class.object_changes_col_is_json?

Expand All @@ -160,7 +160,7 @@ def serialize_attribute_changes(changes)
end
end

def unserialize_attribute_changes(changes)
def unserialize_attribute_changes_for_paper_trail!(changes)
# don't serialize before values before inserting into columns of type `JSON` on `PostgreSQL` databases
return changes if self.paper_trail_version_class.object_changes_col_is_json?

Expand Down Expand Up @@ -332,7 +332,7 @@ def record_update(force = nil)
def changes_for_paper_trail
_changes = changes.delete_if { |k,v| !notably_changed.include?(k) }
if PaperTrail.serialized_attributes?
self.class.serialize_attribute_changes(_changes)
self.class.serialize_attribute_changes_for_paper_trail!(_changes)
end
_changes.to_hash
end
Expand Down Expand Up @@ -447,7 +447,7 @@ def attributes_before_change
def object_attrs_for_paper_trail(attributes_hash)
attrs = attributes_hash.except(*self.paper_trail_options[:skip])
if PaperTrail.serialized_attributes?
self.class.serialize_attributes_for_paper_trail(attrs)
self.class.serialize_attributes_for_paper_trail!(attrs)
end
attrs
end
Expand Down
4 changes: 2 additions & 2 deletions lib/paper_trail/version_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def reify(options = {})
end

if PaperTrail.serialized_attributes?
model.class.unserialize_attributes_for_paper_trail attrs
model.class.unserialize_attributes_for_paper_trail! attrs
end

# Set all the attributes in this version on the model
Expand Down Expand Up @@ -236,7 +236,7 @@ def changeset
_changes = self.class.object_changes_col_is_json? ? object_changes : PaperTrail.serializer.load(object_changes)
@changeset ||= HashWithIndifferentAccess.new(_changes).tap do |changes|
if PaperTrail.serialized_attributes?
item_type.constantize.unserialize_attribute_changes(changes)
item_type.constantize.unserialize_attribute_changes_for_paper_trail!(changes)
end
end
rescue
Expand Down

0 comments on commit 158f260

Please sign in to comment.