Sha256: 7d344057cef40893d3bb17ea69c31ace17690dc81d082d393e6548a033ade7a1

Contents?: true

Size: 840 Bytes

Versions: 4

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Regulations
    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::Regulations::Base.timestamp
      end

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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