Sha256: 84110f9d24736bf381f90a7d9b53db21d4509bb77b7754bc4789abba347bbb0b
Contents?: true
Size: 881 Bytes
Versions: 17
Compression:
Stored size: 881 Bytes
Contents
module Ecom module Core class CrewIdCard < ApplicationRecord before_save :invalidate_other_ids VALID = 'Valid'.freeze INVALID = 'Invalid'.freeze STATUSES = [VALID, INVALID].freeze validates :crew_id, :crew, :issued_on, :valid_until, :status, presence: true validates :status, inclusion: STATUSES validate :valid_until_validator belongs_to :crew def valid_until_validator return unless valid_until && issued_on errors.add(:valid_until, 'cannot be before issue date.') if issued_on >= valid_until end def invalidate_other_ids return if crew_id.nil? return if status_changed?(from: 'Valid', to: 'Invalid') Ecom::Core::CrewIdCard .where(crew_id: crew_id, status: 'Valid') .update(status: 'Invalid') end end end end
Version data entries
17 entries across 17 versions & 1 rubygems