Class: Dynflow::Flows::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/flows/registry.rb

Defined Under Namespace

Classes: IdentifierTaken, UnknownIdentifier

Class Method Summary collapse

Class Method Details

.decode(identifier) ⇒ Object



23
24
25
# File 'lib/dynflow/flows/registry.rb', line 23

def decode(identifier)
  serialization_map[identifier] || raise(UnknownIdentifier, "Could not find mapping for #{identifier}")
end

.encode(klass) ⇒ Object



18
19
20
21
# File 'lib/dynflow/flows/registry.rb', line 18

def encode(klass)
  klass = klass.class unless klass.is_a?(Class)
  serialization_map.invert[klass] || raise(UnknownIdentifier, "Could not find mapping for #{klass}")
end

.register!(klass, identifier) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/dynflow/flows/registry.rb', line 10

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

.serialization_mapObject



27
28
29
# File 'lib/dynflow/flows/registry.rb', line 27

def serialization_map
  @serialization_map ||= {}
end