Class: Logical::Naf::MachineRunnerInvocation

Inherits:
Object
  • Object
show all
Defined in:
app/models/logical/naf/machine_runner_invocation.rb

Constant Summary collapse

COLUMNS =
[
  'id',
  'created_at',
  'machine_runner_id',
  'server_name',
  'pid',
  'status',
  'commit_information',
  'deployment_tag',
  'repository_name'
]

Class Method Summary collapse

Class Method Details

.to_array(column, order, filter) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/logical/naf/machine_runner_invocation.rb', line 19

def self.to_array(column, order, filter)
  machine_runner_invocations = []
  order_by = COLUMNS[column].to_s + ' ' + order

  if order_by =~ /status/
    order_by = "dead_at #{order}, wind_down_at #{order}"
  end

  ::Naf::MachineRunnerInvocation.joins(machine_runner: :machine).choose(filter).order(order_by).all.each do |invocation|
    values = []
    invocation_hash = invocation.attributes
    COLUMNS.each do |key|
      if key == 'created_at'
        values << invocation_hash[key].to_s
      elsif key == 'server_name'
        machine_runner = ::Naf::MachineRunner.find_by_id(invocation_hash['machine_runner_id'])
        values << [machine_runner.machine.id, ::Logical::Naf::Machine.new(machine_runner.machine).name.to_s]
      elsif key == 'status'
        values << invocation.status.gsub('-', ' ').split.map(&:capitalize).join(' ')
      else
        values << invocation_hash[key]
      end
    end
    machine_runner_invocations << values
  end

  machine_runner_invocations
end