Class: Lobster::Serialization::RoomThemeSerializer

Inherits:
Serializer
  • Object
show all
Defined in:
lib/lobster/serialization/room_theme_serializer.rb

Overview

Transforms a room theme to and from its marshaled format.

Instance Method Summary collapse

Instance Method Details

#add_to(engine) ⇒ nil

This method is abstract.

Adds the serializer to an engine.

Parameters:

Returns:

  • (nil)

15
16
17
# File 'lib/lobster/serialization/room_theme_serializer.rb', line 15

def add_to(engine)
  engine.add_serializer(self, Lobster::RoomTheme)
end

#deserialize(data, type, engine, *args) ⇒ Object

Creates a room theme from its marshaled format.

Parameters:

  • data (Object)

    Room theme in its marshaled format.

  • type (Class)

    Type of object that should be created.

  • engine (SerializationEngine)

    Engine performing the serialization. Use this to de-serialize other types of objects.

  • args

    Extra information that might be need for de-serializing.

Returns:

  • (Object)

    Newly created instance of the room theme representative of its marshaled format.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lobster/serialization/room_theme_serializer.rb', line 40

def deserialize(data, type, engine, *args)
  # Raise a format error if any of the keys are missing.
  validate_structure(data, {
                         :id         => Lobster::Uuid,
                         :icon       => Lobster::Uuid,
                         :banner     => Lobster::Uuid,
                         :background => Lobster::Uuid
                         })

  id    = engine.deserialize_inner(data[:id], Lobster::Uuid)
  theme = Lobster::RoomTheme.new(id)

  theme.icon_id       = engine.deserialize_inner(data[:icon], Lobster::Uuid)
  theme.banner_id     = engine.deserialize_inner(data[:banner], Lobster::Uuid)
  theme.background_id = engine.deserialize_inner(data[:background], Lobster::Uuid)

  theme
end

#serialize(obj, engine) ⇒ Object

Converts a room theme to its marshaled format.

Parameters:

  • obj (RoomTheme)

    Room to serialize.

  • engine (SerializationEngine)

    Engine performing the serialization. Use this to serialize other types of objects.

Returns:

  • (Object)

    Room theme marshaled to its simplest form.


24
25
26
27
28
29
30
31
# File 'lib/lobster/serialization/room_theme_serializer.rb', line 24

def serialize(obj, engine)
  {
      :id         => engine.serialize_inner(obj.id),
      :icon       => engine.serialize_inner(obj.icon_id),
      :banner     => engine.serialize_inner(obj.banner_id),
      :background => engine.serialize_inner(obj.background_id),
  }
end