Sha256: 8fac38cf4119be2d0ed519c17cd5b303249e0199e2bc18ba8fd63adb4844c049

Contents?: true

Size: 998 Bytes

Versions: 73

Compression:

Stored size: 998 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, created_at: :asc) }
      scope :reversed, -> { order(started_on: :desc, created_at: :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

73 entries across 73 versions & 1 rubygems

Version Path
renalware-core-2.0.106 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.105 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.104 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.103 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.102 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.101 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.100 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.99 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.98 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.97 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.96 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.95 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.94 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.93 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.92 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.91 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.90 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.89 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.88 app/models/renalware/transplants/registration_status.rb
renalware-core-2.0.87 app/models/renalware/transplants/registration_status.rb