class Synapse::Serialization::AttributeSerializer

Implementation of a serializer that uses the hashing features of ActiveModel and Virtus

If the object being serialized or deserialized is a hash, it will be untouched

Objects being serialized by this implementation must meet the following requirements:

If either one of these are not met, the serializer may fail instantly or the deserialized object could be put in a bad state

Protected Instance Methods

native_content_type() click to toggle source

@return [Class]

# File lib/synapse/serialization/serializer/attribute.rb, line 43
def native_content_type
  Hash
end
perform_deserialize(content, type) click to toggle source

@param [Object] content @param [Class] type @return [Object]

# File lib/synapse/serialization/serializer/attribute.rb, line 31
def perform_deserialize(content, type)
  if Hash == type
    content
  else
    # Allocate the target object but don't call #initialize
    object = type.allocate
    object.attributes = content
    object
  end
end
perform_serialize(content) click to toggle source

@param [Object] content @return [Object]

# File lib/synapse/serialization/serializer/attribute.rb, line 20
def perform_serialize(content)
  if content.is_a? Hash
    content
  else
    content.attributes
  end
end