Class: EvilEvents::Core::Events::Serializers::JSON::Engines::Native Private

Inherits:
Base::AbstractEngine show all
Defined in:
lib/evil_events/core/events/serializers/json/engines/native.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.

Since:

  • 0.4.0

Instance Method Summary collapse

Methods inherited from Base::AbstractEngine

#initialize, #restore_serialization_state

Constructor Details

This class inherits a constructor from EvilEvents::Core::Events::Serializers::Base::AbstractEngine

Instance Method Details

#dump(serialization_state) ⇒ String

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.

Parameters:

Returns:

  • (String)

Since:

  • 0.4.0



12
13
14
15
16
17
18
19
# File 'lib/evil_events/core/events/serializers/json/engines/native.rb', line 12

def dump(serialization_state)
  ::JSON.generate(
    id:       serialization_state.id,
    type:     serialization_state.type,
    payload:  serialization_state.payload,
    metadata: serialization_state.
  )
end

#load(json_string) ⇒ EventSerializationState

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.

Parameters:

  • json_string (String)

Returns:

  • (EventSerializationState)

Raises:

Since:

  • 0.4.0



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/evil_events/core/events/serializers/json/engines/native.rb', line 27

def load(json_string)
  json = ::JSON.parse(json_string, symbolize_names: true)

  restore_serialization_state(
    id:       json[:id],
    type:     json[:type],
    payload:  json[:payload],
    metadata: json[:metadata]
  )
rescue ::JSON::ParserError, TypeError
  raise EvilEvents::SerializationEngineError
end