Sha256: 401592cd527c7a29f5ea4174cda9f6550bf8f5cfa787c67b97af078586644700

Contents?: true

Size: 732 Bytes

Versions: 5

Compression:

Stored size: 732 Bytes

Contents

module ActiveRegulation
  module Quarantine
    extend ActiveSupport::Concern

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

    def quarantine!
      update(quarantined_at: Time.now) if unquarantined?
    end

    def unquarantine!
      update(quarantined_at: nil) if quarantined?
    end

    def quarantined?
      !unquarantined?
    end

    def unquarantined?
      quarantined_at.nil?
    end

    def quarantined_at_or_time
      unquarantined? ? Time.now : quarantined_at
    end

    def to_quarantine
      I18n.t("active_regulation.quarantine.#{unquarantined? ? :unquarantined : :quarantined}")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_regulation-4.0.3 lib/active_regulation/quarantine.rb
active_regulation-4.0.2 lib/active_regulation/quarantine.rb
active_regulation-4.0.1 lib/active_regulation/quarantine.rb
active_regulation-4.0.0 lib/active_regulation/quarantine.rb
active_regulation-3.0.0 lib/active_regulation/quarantine.rb