Sha256: 8029c69b763ecc091a0201277056d177e15e04d27e783dfde99232a4157cffe0

Contents?: true

Size: 662 Bytes

Versions: 5

Compression:

Stored size: 662 Bytes

Contents

module ActiveRegulation
  module Visibility
    extend ActiveSupport::Concern

    included do
      scope :visible, -> { where(invisible_at: nil) }
      scope :invisible, -> { where.not(invisible_at: nil) }
    end

    def invisible!
      update(invisible_at: Time.now) if visible?
    end

    def visible!
      update(invisible_at: nil) if invisible?
    end

    def invisible?
      !visible?
    end

    def visible?
      invisible_at.nil?
    end

    def invisible_at_or_time
      visible? ? Time.now : invisible_at
    end

    def to_visibility
      I18n.t("active_regulation.visibility.#{visible? ? :visible : :invisible}")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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