Sha256: ff98d96cb76a34050bbe864e5a6e0bee94981cd5854a7a0da8c23dd9f0bac39d

Contents?: true

Size: 906 Bytes

Versions: 13

Compression:

Stored size: 906 Bytes

Contents

module Ecom
  module Core
    class SiteCrew < ApplicationRecord
      TEMPORARY_SITE_CREW = 'Temporary site crew'.freeze
      PERMANENT_SITE_CREW = 'Permanent site crew'.freeze

      SITE_CREW_TYPES = [TEMPORARY_SITE_CREW, PERMANENT_SITE_CREW].freeze

      ACTIVE = 'Active'.freeze
      INACTIVE = 'Inactive'.freeze
      STATUSES = [ACTIVE, INACTIVE].freeze

      validates :crew_id, :crew, :site_id, :site, :start_date, :site_crew_type, :status, presence: true

      validates_uniqueness_of :site_id,
                              scope: :crew_id,
                              if: -> { status == 'Active' },
                              message: 'There can only be one record with status `Active` for a given site and crew'

      validates :site_crew_type, inclusion: SITE_CREW_TYPES
      validates :status, inclusion: STATUSES

      belongs_to :crew
      belongs_to :site
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ecom_core-1.3.11 app/models/ecom/core/site_crew.rb
ecom_core-1.3.10 app/models/ecom/core/site_crew.rb
ecom_core-1.3.9 app/models/ecom/core/site_crew.rb
ecom_core-1.3.8 app/models/ecom/core/site_crew.rb
ecom_core-1.3.7 app/models/ecom/core/site_crew.rb
ecom_core-1.3.6 app/models/ecom/core/site_crew.rb
ecom_core-1.3.5 app/models/ecom/core/site_crew.rb
ecom_core-1.3.4 app/models/ecom/core/site_crew.rb
ecom_core-1.3.3 app/models/ecom/core/site_crew.rb
ecom_core-1.3.2 app/models/ecom/core/site_crew.rb
ecom_core-1.3.1 app/models/ecom/core/site_crew.rb
ecom_core-1.3.0 app/models/ecom/core/site_crew.rb
ecom_core-1.2.36 app/models/ecom/core/site_crew.rb