Class: TemplateInvocation::TaskResultMap

Inherits:
Object
  • Object
show all
Defined in:
app/models/template_invocation.rb

Constant Summary collapse

MAP =
{
  :cancelled => :cancelled,
  :error     => :failed,
  :pending   => :pending,
  :running   => :pending,
  :success   => :success,
  :warning   => :failed,
}.with_indifferent_access
REVERSE_MAP =
MAP.each_with_object({}) do |(key, value), acc|
  acc[value] ||= []
  acc[value] << key
end.with_indifferent_access

Class Method Summary collapse

Class Method Details

.resultsObject



49
50
51
# File 'app/models/template_invocation.rb', line 49

def results
  MAP.keys.map(&:to_sym)
end

.status_to_task_result(status) ⇒ Object

1:n failed => [:error, :warning]



65
66
67
68
69
70
71
# File 'app/models/template_invocation.rb', line 65

def status_to_task_result(status)
  if REVERSE_MAP.key? status
    REVERSE_MAP[status].map(&:to_sym)
  else
    Array(status)
  end
end

.statusesObject



53
54
55
# File 'app/models/template_invocation.rb', line 53

def statuses
  REVERSE_MAP.keys.map(&:to_sym)
end

.task_result_to_status(result) ⇒ Object

1:1 error => failed



59
60
61
# File 'app/models/template_invocation.rb', line 59

def task_result_to_status(result)
  MAP[result].try(:to_sym) || result
end