Sha256: ff63ead4e593a3ca1bc15ba544da96bd9acd3316cce93bafa5bc4ce473a58adb

Contents?: true

Size: 693 Bytes

Versions: 5

Compression:

Stored size: 693 Bytes

Contents

module ActiveRegulation
  module Containment
    extend ActiveSupport::Concern

    included do
      scope :contained, -> { where.not(contained_at: nil) }
      scope :uncontained, -> { where(contained_at: nil) }
    end

    def contain!
      update(contained_at: Time.now) if uncontained?
    end

    def uncontain!
      update(contained_at: nil) if contained?
    end

    def contained?
      !uncontained?
    end

    def uncontained?
      contained_at.nil?
    end

    def contained_at_or_time
      uncontained? ? Time.now : contained_at
    end

    def to_containment
      I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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