class DraftApprove::Serialization::Json::Serializer
Logic for serializing changes to ActiveRecord models into JSON format, and deserializing the changes on a Draft
object into the new values for an ActiveRecord model.
@api private
Public Class Methods
changes_for_model(model)
click to toggle source
Serialize changes on an ActiveRecord model into a JSON representation of the changes.
@param model [Object] the acts_as_draftable
ActiveRecord model whose
changes will be serialized to JSON
@return [Hash] a hash representation of the changes to the given
model, which can be automatically converted to JSON if persisted to a JSON formatted database column
# File lib/draft_approve/serialization/json/serializer.rb, line 23 def self.changes_for_model(model) JsonSerializer.new(model).changes_for_model end
new_values_for_draft(draft)
click to toggle source
Deserialize changes from a Draft
object into the new values for the acts_as_draftable
ActiveRecord model the draft relates to.
@param draft [Draft] the Draft
whose changes will be deserialized
@return [Hash] a hash representation of the new values for the object
the given draft relates to.
@example
draft = Person.new(name: 'Joe Bloggs').save_draft! Json::Serializer.new_values_for_draft(draft) #=> { "name" => [nil, "Joe Bloggs"] }
# File lib/draft_approve/serialization/json/serializer.rb, line 39 def self.new_values_for_draft(draft) JsonDeserializer.new(draft).new_values_for_draft end