Sha256: 2f9ed0ab1c6cdbb2b2cb508ff2df3c0fbff1d89d1d159d6bb3fa28407bb21374

Contents?: true

Size: 961 Bytes

Versions: 58

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/transplants"

module Renalware
  module Transplants
    class RegistrationStatus < ApplicationRecord
      include Accountable

      belongs_to :description, class_name: "RegistrationStatusDescription"
      belongs_to :registration, touch: true

      scope :ordered, -> { order(started_on: :asc) }
      scope :reversed, -> { order(started_on: :desc) }

      validates :description_id, presence: true
      validates :started_on, timeliness: { type: :date, allow_blank: false }
      validates :terminated_on, timeliness: { type: :date, allow_blank: true }

      validate :constraint_started_on_today_or_before, if: :started_on

      def terminated?
        terminated_on.present?
      end

      def constraint_started_on_today_or_before
        errors.add(:started_on, :invalid) if started_on > Time.zone.today
      end

      def to_s
        description&.to_s
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
renalware-core-2.0.73 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.72 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.71 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.70 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.69 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.68 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.67 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.64 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.63 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.62 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.61 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.60 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.58 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.57 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.56 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.55 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.54 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.53 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.52 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.51 app/models/renalware/transplants/registration_status.rb