Sha256: 51fbaf0ca85650a41801dedb97ad889575b4f736c4a97f89ad055a14d22f6c57

Contents?: true

Size: 941 Bytes

Versions: 17

Compression:

Stored size: 941 Bytes

Contents

module Ecom
  module Core
    class TaskTemplate < ApplicationRecord
      has_ancestry

      belongs_to :task_template_type
      has_and_belongs_to_many :work_product_templates, join_table: 'ecom_core_task_templates_work_product_templates'
      has_and_belongs_to_many :resource_types, join_table: 'ecom_core_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::Core::CrewType')
      end

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

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ecom_core-1.2.31 app/models/ecom/core/task_template.rb
ecom_core-1.2.30 app/models/ecom/core/task_template.rb
ecom_core-1.2.29 app/models/ecom/core/task_template.rb
ecom_core-1.2.28 app/models/ecom/core/task_template.rb
ecom_core-1.2.27 app/models/ecom/core/task_template.rb
ecom_core-1.2.26 app/models/ecom/core/task_template.rb
ecom_core-1.2.25 app/models/ecom/core/task_template.rb
ecom_core-1.2.24 app/models/ecom/core/task_template.rb
ecom_core-1.2.23 app/models/ecom/core/task_template.rb
ecom_core-1.2.22 app/models/ecom/core/task_template.rb
ecom_core-1.2.21 app/models/ecom/core/task_template.rb
ecom_core-1.2.20 app/models/ecom/core/task_template.rb
ecom_core-1.2.19 app/models/ecom/core/task_template.rb
ecom_core-1.2.18 app/models/ecom/core/task_template.rb
ecom_core-1.2.17 app/models/ecom/core/task_template.rb
ecom_core-1.2.16 app/models/ecom/core/task_template.rb
ecom_core-1.2.15 app/models/ecom/core/task_template.rb