Sha256: 1b8dfd7f8f4dc22a0600e354d8c7cfe83b87d30934594d5175dccd3cf1c82f0a
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true module RailsWorkflow # Process stores service information including links to process template, # all operations, parent operation, context etc. class Process < ActiveRecord::Base include Status include HasContext belongs_to :template, class_name: 'RailsWorkflow::ProcessTemplate' has_many :operations, class_name: 'RailsWorkflow::Operation' has_one :parent_operation, class_name: 'RailsWorkflow::Operation', foreign_key: :child_process_id alias parent parent_operation has_many :workflow_errors, class_name: 'RailsWorkflow::Error', as: :parent delegate :data, to: :context scope :by_status, ->(status) { where(status: status) } def manager @manager ||= template.manager_class.new(self) end def self.count_by_statuses query = RailsWorkflow.config.sql_dialect::COUNT_STATUSES statuses = connection.select_all(query).rows statuses_array.map do |status| statuses.detect { |s| s.first.to_i == status }.try(:last).to_i end end def self.statuses_array (NOT_STARTED..ROLLBACK).to_a end def uncompleted? uncompleted_statuses.include?(status) && uncompleted_operations.size.zero? end # Returns set or operation that not yet completed. # Operation complete in DONE, SKIPPED, CANCELED, etc many other statuses def uncompleted_operations operations.reject(&:completed?) end def can_start? [Status::NOT_STARTED, Status::IN_PROGRESS] .include?(status) && !operations.empty? end def unresolved_errors workflow_errors.unresolved.where.not(id: id) end def complete self.status = Status::DONE save end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_workflow-0.4.4 | app/models/rails_workflow/process.rb |