Class: TaskinatorUi::ProcessDecorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/decorators/taskinator_ui/process_decorator.rb

Constant Summary collapse

STATUS_COLORS =
{
  initial: 'primary',
  enqueued: 'primary',
  processing: 'info',
  paused: 'warning',
  resumed: 'warning',
  completed: 'success',
  cancelled: 'warning',
  failed: 'danger',
}

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ ProcessDecorator

Returns a new instance of ProcessDecorator.



14
15
16
17
18
19
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 14

def initialize(obj)
  obj = obj.__getobj__ if obj.is_a?(Delegator)
  obj = obj.sub_process if obj.is_a?(Taskinator::Task::SubProcess)

  super(obj.is_a?(Delegator) ? obj.__getobj__ : obj)
end

Instance Method Details

#class_nameObject



48
49
50
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 48

def class_name
  __getobj__.class.name
end

#html_uuidObject



34
35
36
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 34

def html_uuid
  uuid.gsub(':', '').html_safe
end

#jobObject



56
57
58
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 56

def job
  __getobj__.is_a?(Taskinator::Task::Job) ? __getobj__.job : nil
end

#methodObject



52
53
54
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 52

def method
  __getobj__.is_a?(Taskinator::Task::Step) ? __getobj__.method : nil
end

#pending_tasksObject



38
39
40
41
42
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 38

def pending_tasks
  @pending_tasks ||= Taskinator.redis do |conn|
    conn.get("#{key}.pending")
  end
end

#status_badgeObject



44
45
46
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 44

def status_badge
  "<span class=\"badge bg-#{STATUS_COLORS[current_state]}\">#{current_state}</span>".html_safe
end

#titleObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/decorators/taskinator_ui/process_decorator.rb', line 21

def title
  case __getobj__
  when Taskinator::Task::Step
    "Task <b>#{method}</b>"
  when Taskinator::Task::Job
    "Job <b>#{job}</b>"
  when Taskinator::Process
    "#{__getobj__.class.name.split('::').last}"
  else
    __getobj__.inspect
  end.html_safe
end