Sha256: e15c864ca51c96a5e5da30b69240c37dce5f1c76ee52ebdfc5f1039adda6240b

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module RailsWorkflow
  class OperationTemplate < ActiveRecord::Base
    include OperationStatus
    include RailsWorkflow::Uuid
    include OperationTemplates::Dependencies
    include OperationTemplates::Assignments

    belongs_to :process_template, class_name: 'RailsWorkflow::ProcessTemplate'
    belongs_to :child_process, class_name: 'RailsWorkflow::ProcessTemplate', required: false

    scope :other_operations, ->(process_template_id, operation_template_id) {
      where(process_template_id: process_template_id)
        .where.not(id: operation_template_id)
    }

    def other_operations
      OperationTemplate.other_operations(process_template_id, id)
    end

    class << self
      def types
        RailsWorkflow.config.operation_types
      end
    end

    def operation_class
      get_class(:operation_class, default_class(kind.to_sym))
    end

    def default_type
      RailsWorkflow.config.default_operation_template_type
    end

    private

    def default_class(kind)
      RailsWorkflow.config.operation_types[kind][:class]
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_workflow-0.4.4 app/models/rails_workflow/operation_template.rb
rails_workflow-0.4.3 app/models/rails_workflow/operation_template.rb
rails_workflow-0.4.2 app/models/rails_workflow/operation_template.rb