Class: DraftApprove::Serialization::Json::Serializer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/draft_approve/serialization/json/serializer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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.

Class Method Summary collapse

Class Method Details

.changes_for_model(model) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize changes on an ActiveRecord model into a JSON representation of the changes.

Parameters:

  • model (Object)

    the acts_as_draftable ActiveRecord model whose changes will be serialized to JSON

Returns:

  • (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



23
24
25
# 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) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deserialize changes from a Draft object into the new values for the acts_as_draftable ActiveRecord model the draft relates to.

Examples:

draft = Person.new(name: 'Joe Bloggs').save_draft!
Json::Serializer.new_values_for_draft(draft)
#=> { "name" => [nil, "Joe Bloggs"] }

Parameters:

  • draft (Draft)

    the Draft whose changes will be deserialized

Returns:

  • (Hash)

    a hash representation of the new values for the object the given draft relates to.



39
40
41
# 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