Sha256: d56e4c4e137e61467f348be5e0295765f386b6618ee4d76428ad400de1013c5f

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 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'

    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

2 entries across 2 versions & 1 rubygems

Version Path
rails_workflow-0.4.1 app/models/rails_workflow/operation_template.rb
rails_workflow-0.4.0 app/models/rails_workflow/operation_template.rb