Sha256: 2a6705fa99a7b46cd43ab26085c8853497b88e79bc9d727134698572d0c42906

Contents?: true

Size: 866 Bytes

Versions: 5

Compression:

Stored size: 866 Bytes

Contents

module Ecom
  module Model
    class TaskTemplate < ApplicationRecord
      has_ancestry

      belongs_to :task_template_type
      has_one :work_product_template
      has_and_belongs_to_many :resource_types, join_table: 'ecom_model_task_templates_resource_types'

      validates :name, :code, presence: true
      validates :code, uniqueness: true
      delegate(:name, to: :task_template_type, prefix: true)

      def full_name
        parent_name = parent&.name
        return name unless parent_name

        "#{name} - #{parent_name}"
      end

      def crew_types
        resource_types.where(type: 'Ecom::Model::CrewType')
      end

      def material_types
        resource_types.where(type: 'Ecom::Model::MaterialType')
      end

      def equipment_types
        resource_types.where(type: 'Ecom::Model::EquipmentType')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecom_model-2.0.4 app/models/ecom/model/task_template.rb
ecom_model-2.0.3 app/models/ecom/model/task_template.rb
ecom_model-2.0.2 app/models/ecom/model/task_template.rb
ecom_model-2.0.1 app/models/ecom/model/task_template.rb
ecom_model-2.0.0 app/models/ecom/model/task_template.rb