Sha256: 94fb4aa4c6db602eb412b746ce305824a0b1d50a79fe2ab80f33761aa842e538

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Regulation
    module Activation

      extend ActiveSupport::Concern

      included do
        scope :active, -> { where(inactivated_at: nil) }
        scope :inactive, -> { where.not(inactivated_at: nil) }
      end

      def active!
        return true if active?

        update(inactivated_at: nil)
      end

      def active?
        inactivated_at.nil?
      end

      def inactive!
        return true if inactive?

        update(inactivated_at: Time.current)
      end

      def inactive?
        !active?
      end

      def inactivated_at_or_time
        return inactivated_at if inactive?

        Lite::Regulation::Base.timestamp
      end

      def to_activation
        I18n.t("lite.regulation.activation.#{:in if inactive?}active")
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lite-regulation-1.0.1 lib/lite/regulation/activation.rb
lite-regulation-1.0.0 lib/lite/regulation/activation.rb