Sha256: 564f9dc2cfe1184c79e7b275d1871e818ddfd157022089cc8a6d80a7fcb4aa93
Contents?: true
Size: 1.21 KB
Versions: 12
Compression:
Stored size: 1.21 KB
Contents
module Euston class EventHeaders attr_reader :id, :type, :version, :timestamp, :source_message, :source_message_type def initialize id, type, version, timestamp = Time.now, source_message = nil, source_message_type = nil @id = id @type = type @version = version @timestamp = Time.at(timestamp).utc @source_message = source_message @source_message_type = source_message_type end def to_hash Hash[@source_message_type, @source_message].merge :id => id, :type => type, :version => version, :timestamp => timestamp end def self.from_hash hash if hash.has_key? :command source_message = hash[:command] source_message_type = :command elsif hash.has_key? :event_subscription source_message = hash[:event_subscription] source_message_type = :event_subscription end self.new hash[:id], hash[:type].to_sym, hash[:version], hash[:timestamp], source_message, source_message_type end def to_s "#{id} #{type} (v#{version})" end end end
Version data entries
12 entries across 12 versions & 1 rubygems