Class: Synapse::ProcessManager::Mongo::ProcessDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/process_manager/mongo/process_document.rb

Overview

Mongo document that represents a process instance

Instance Method Summary collapse

Instance Method Details

#from_hash(hash) ⇒ ProcessDocument

Parameters:

  • hash (Hash)

Returns:



31
32
33
34
35
36
37
38
39
40
# File 'lib/synapse/process_manager/mongo/process_document.rb', line 31

def from_hash(hash)
  hash.symbolize_keys!

  @id = hash.fetch :_id
  @serialized = hash.fetch :serialized
  @type = hash.fetch :type
  @correlations = hash.fetch :correlations

  self
end

#from_process(process, serializer) ⇒ ProcessDocument

Parameters:

  • process (Process)
  • serializer (Serializer)

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/synapse/process_manager/mongo/process_document.rb', line 9

def from_process(process, serializer)
  serialized_process = serializer.serialize process, String

  @id = process.id
  @serialized = serialized_process.content
  @type = serialized_process.type.name
  @correlations = Array.new

  process.correlations.each do |correlation|
    correlation_hash = {
      key: correlation.key,
      value: correlation.value
    }

    @correlations.push correlation_hash
  end

  self
end

#to_hashHash

Returns:

  • (Hash)


43
44
45
46
47
48
# File 'lib/synapse/process_manager/mongo/process_document.rb', line 43

def to_hash
  { _id: @id,
    serialized: @serialized,
    type: @type,
    correlations: @correlations }
end

#to_process(serializer) ⇒ Process

Parameters:

  • serializer (Serializer)

Returns:

  • (Process)


52
53
54
55
56
57
# File 'lib/synapse/process_manager/mongo/process_document.rb', line 52

def to_process(serializer)
  serialized_type = Serialization::SerializedType.new @type, nil
  serialized_object = Serialization::SerializedObject.new @serialized, String, serialized_type

  serializer.deserialize serialized_object
end