Class: Representors::Serialization::HaleSerializer

Inherits:
HalSerializer show all
Defined in:
lib/representors/serialization/hale_serializer.rb

Constant Summary collapse

SEMANTIC_TYPES =
{
  select: "text", #No way in Crichton to distinguish [Int] and [String]
  search:"text",
  text: "text",
  boolean: "bool", #a Server should accept ?cat&dog or ?cat=cat&dog=dog
  number: "number",
  email: "text",
  tel: "text",
  datetime: "text",
  time: "text",
  date: "text",
  month: "text",
  week: "text",
  object: "object",
  :"datetime-local" => "text"
}

Constants inherited from HalSerializer

Representors::Serialization::HalSerializer::EMBEDDED_KEY, Representors::Serialization::HalSerializer::LINKS_KEY, Representors::Serialization::HalSerializer::LINKS_ONLY_OPTION

Instance Attribute Summary

Attributes inherited from Representors::SerializationBase

#target

Instance Method Summary collapse

Methods inherited from Representors::SerializerBase

inherited, #initialize

Methods inherited from Representors::SerializationBase

media_symbols, media_types

Methods included from RepresentorSupport::Utilities

#deep_dup, #dup_or_self, #map_or_apply, #symbolize_keys

Constructor Details

This class inherits a constructor from Representors::SerializerBase

Instance Method Details

#to_hash(options = {}) ⇒ Object

This is public and returning a hash to be able to implement embedded resources serialization TODO: make this private and merge with to_media_type The name is quite misleading,



29
30
31
32
33
34
# File 'lib/representors/serialization/hale_serializer.rb', line 29

def to_hash(options ={})
  base_hash, links, embedded_hales = common_serialization(@target)
  meta = get_data_lists(@target)
  base_hash.merge!(meta).merge!(links).merge!(embedded_hales.(options))
  base_hash
end

#to_media_type(options = {}) ⇒ Object

This is the main entry of this class. It returns a serialization of the data in a given media type.



39
40
41
# File 'lib/representors/serialization/hale_serializer.rb', line 39

def to_media_type(options = {})
  to_hash(options).to_json
end