Sha256: 1cb6ddde7ab6c5c46edac64649a7281d7a848545f6b1919024734aa4c3336b29
Contents?: true
Size: 977 Bytes
Versions: 15
Compression:
Stored size: 977 Bytes
Contents
# frozen_string_literal: true module Dynflow module Flows class Registry class IdentifierTaken < ArgumentError; end class UnknownIdentifier < ArgumentError; end class << self def register!(klass, identifier) if (found = serialization_map[identifier]) raise IdentifierTaken, "Error setting up mapping #{identifier} to #{klass}, it already maps to #{found}" else serialization_map.update(identifier => klass) end end def encode(klass) klass = klass.class unless klass.is_a?(Class) serialization_map.invert[klass] || raise(UnknownIdentifier, "Could not find mapping for #{klass}") end def decode(identifier) serialization_map[identifier] || raise(UnknownIdentifier, "Could not find mapping for #{identifier}") end def serialization_map @serialization_map ||= {} end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems