Module: Libis::Workflow::Status
- Included in:
- Base::WorkItem
- Defined in:
- lib/libis/workflow/status.rb
Instance Method Summary collapse
-
#check_status(state, task = nil) ⇒ Boolean
Check status of the object.
-
#compare_status(state, task = nil) ⇒ Integer
Compare status with current status of the object.
-
#set_status(task, status) ⇒ Object
Changes the status of the object.
-
#status(task = nil) ⇒ Symbol
Get last known status symbol for a given task.
-
#status_label(task = nil) ⇒ String
Gets the last known status label of the object.
-
#status_progress(task, progress = nil, max = nil) ⇒ Object
Update the progress of the working task.
-
#status_text(task = nil) ⇒ Symbol
Get last known status text for a given task.
Instance Method Details
#check_status(state, task = nil) ⇒ Boolean
Check status of the object.
74 75 76 |
# File 'lib/libis/workflow/status.rb', line 74 def check_status(state, task = nil) self.status(task) == state end |
#compare_status(state, task = nil) ⇒ Integer
Compare status with current status of the object.
82 83 84 |
# File 'lib/libis/workflow/status.rb', line 82 def compare_status(state, task = nil) STATUS[self.status(task)] <=> STATUS[state] end |
#set_status(task, status) ⇒ Object
Changes the status of the object. The status changed is logged in the status_log with the current timestamp.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/libis/workflow/status.rb', line 31 def set_status(task, status) task = task.namepath if task.is_a?(Libis::Workflow::Task) log_entry = self.status_entry(task) if log_entry.nil? || STATUS[status_symbol(log_entry['status'])] > STATUS[status_symbol(status)] log_entry = self.add_status_log('task' => task, 'status' => status, 'created' => DateTime.now) end log_entry['status'] = status log_entry['updated'] = DateTime.now self.save_log_entry(log_entry) end |
#status(task = nil) ⇒ Symbol
Get last known status symbol for a given task
46 47 48 49 |
# File 'lib/libis/workflow/status.rb', line 46 def status(task = nil) entry = self.status_entry(task) status_symbol(entry['status']) rescue :NOT_STARTED end |
#status_label(task = nil) ⇒ String
Gets the last known status label of the object.
64 65 66 67 |
# File 'lib/libis/workflow/status.rb', line 64 def status_label(task = nil) entry = self.status_entry(task) "#{entry['task'] rescue nil}#{entry['status'].capitalize rescue nil}" end |
#status_progress(task, progress = nil, max = nil) ⇒ Object
Update the progress of the working task
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/libis/workflow/status.rb', line 90 def status_progress(task, progress = nil, max = nil) log_entry = self.status_entry(task) if log_entry.nil? || STATUS[status_symbol(log_entry['status'])] >= STATUS[:DONE] log_entry = self.add_status_log('task' => task, 'status' => :STARTED, 'created' => DateTime.now) end log_entry['progress'] = progress ? progress : (log_entry['progress'] || 0) + 1 log_entry['max'] = max if max log_entry['updated'] = DateTime.now self.save_log_entry(log_entry) end |
#status_text(task = nil) ⇒ Symbol
Get last known status text for a given task
55 56 57 58 |
# File 'lib/libis/workflow/status.rb', line 55 def status_text(task = nil) entry = self.status_entry(task) status_string(entry['status']) rescue STATUS_TEXT.first end |