Sha256: a0ac0ca56e4fadb8fb0693f6a66dec4be3974f45f7e726520e62aa08b305ea31

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

module RailsWorkflow
  class ProcessTemplate < ActiveRecord::Base
    include ProcessTemplates::DefaultBuilder
    include RailsWorkflow::Uuid
    has_many :operations, -> { order(id: :asc)},  :class_name => 'OperationTemplate'


    def other_processes
      ProcessTemplate.where.not(id: self.id)
    end


    # we try to read process class from template
    # and set default Workflow::Process if blank process_class on template
    def process_class
      get_class_for :process_class,
                    RailsWorkflow.config.process_class
    end

    def manager_class
      get_class_for(:manager_class,
                    RailsWorkflow.config.manager_class)
    end

    def independent_operations
      operations.independent_only.to_a
    end

    # here we calculate template operations that depends on
    # given process operation status and template id
    def dependent_operations operation
      operations.select do |top|
        top.dependencies.select do |dp|
          dp['id'] == operation.template.id && dp['statuses'].include?(operation.status)
        end.present?
      end
    end

    private
    # we try to read manager class from process template
    # otherwise use default

    def get_class_for symb, default
      (read_attribute(symb).presence || default).constantize
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_workflow-0.3.7 app/models/rails_workflow/process_template.rb
rails_workflow-0.3.6 app/models/rails_workflow/process_template.rb
rails_workflow-0.3.5 app/models/rails_workflow/process_template.rb
rails_workflow-0.3.4 app/models/rails_workflow/process_template.rb
rails_workflow-0.3.3 app/models/rails_workflow/process_template.rb