Sha256: 05df7e04c38309575c13e679dde25371f09a1083a4df50d86a95746783a30dbf

Contents?: true

Size: 898 Bytes

Versions: 4

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Regulations
    module Quarantine

      extend ActiveSupport::Concern

      included do
        scope :quarantined, -> { where.not(quarantined_at: nil) }
        scope :unquarantined, -> { where(quarantined_at: nil) }
      end

      def quarantine!
        return true if quarantined?

        update(quarantined_at: Time.current)
      end

      def quarantined?
        !unquarantined?
      end

      def quarantined_at_or_time
        return quarantined_at if quarantined?

        Lite::Regulations::Base.timestamp
      end

      def to_quarantine
        I18n.t("lite.regulations.quarantine.#{:un if unquarantined?}quarantined")
      end

      def unquarantine!
        return true if unquarantined?

        update(quarantined_at: nil)
      end

      def unquarantined?
        quarantined_at.nil?
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lite-regulations-1.1.2 lib/lite/regulations/quarantine.rb
lite-regulations-1.1.1 lib/lite/regulations/quarantine.rb
lite-regulations-1.1.0 lib/lite/regulations/quarantine.rb
lite-regulations-1.0.0 lib/lite/regulations/quarantine.rb