Sha256: 7197c1acc5e8e383283ef3af76ce21bf138f89f8442e97e592c259d6c031f694

Contents?: true

Size: 901 Bytes

Versions: 5

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

module Emittance
  module Resque
    module EventSerializer
      ##
      # The default serializer for Emittance::Resque. Converts the event with its properties into a hash, and
      # deserializes that hash by initializing a new event with those properties.
      #
      module Default
        class << self
          def serialize(event)
            {
              identifier: event.identifiers.first,
              emitter: event.emitter,
              timestamp: event.timestamp,
              payload: event.payload
            }
          end

          def deserialize(event_hash)
            identifier = event_hash[:identifier]
            event_klass = Emittance::EventLookup.find_event_klass(identifier)

            event_klass.new(event_hash[:emitter], event_hash[:timestamp], event_hash[:payload])
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
emittance-resque-1.1.0 lib/emittance/resque/event_serializer/default.rb
emittance-resque-1.0.0 lib/emittance/resque/event_serializer/default.rb
emittance-resque-0.2.0 lib/emittance/resque/event_serializer/default.rb
emittance-resque-0.1.1 lib/emittance/resque/event_serializer/default.rb
emittance-resque-0.1.0 lib/emittance/resque/event_serializer/default.rb