Class: Minicron::Hub::JobExecutionOutputSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/minicron/hub/serializers/job_execution_output.rb

Instance Method Summary collapse

Constructor Details

#initialize(job_execution_outputs) ⇒ JobExecutionOutputSerializer

Returns a new instance of JobExecutionOutputSerializer.


4
5
6
# File 'lib/minicron/hub/serializers/job_execution_output.rb', line 4

def initialize(job_execution_outputs)
  @job_execution_outputs = job_execution_outputs
end

Instance Method Details

#do_serialization(job_execution_output) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/minicron/hub/serializers/job_execution_output.rb', line 25

def do_serialization(job_execution_output)
  new_job_execution_output = {}

  # Add all the normal attributes of the job_execution_output
  job_execution_output.attributes.each do |key, value|
    # Remove _id from keys
    key = key[-3, 3] == '_id' ? key[0..-4] : key
    new_job_execution_output[key] = value
  end

  # Add the execution to the sideloaded data
  new_execution = {}
  job_execution_output.execution.attributes.each do |key, value|
    # Remove _id from keys
    key = key[-3, 3] == '_id' ? key[0..-4] : key

    new_execution[key] = value
  end

  # Append the new execution to the @response
  @response[:executions].push(new_execution)

  # Append the new job_execution_output to the @response
  @response[:job_execution_outputs].push(new_job_execution_output)
end

#serializeObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/minicron/hub/serializers/job_execution_output.rb', line 8

def serialize
  @response = {
    :job_execution_outputs => [],
    :executions => []
  }

  if @job_execution_outputs.respond_to? :each
    @job_execution_outputs.each do |job_execution_output|
      do_serialization(job_execution_output)
    end
  else
    do_serialization(@job_execution_outputs)
  end

  @response
end