Sha256: fd79504c17e3ec5107a9359d740b2f6f0306983c4a9536e2e72c576d7d2be042

Contents?: true

Size: 582 Bytes

Versions: 6

Compression:

Stored size: 582 Bytes

Contents

module ActiveRegulation
  module Activation
    extend ActiveSupport::Concern

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

    def active!
      update(inactivated_at: nil) if inactive?
    end

    def inactive!
      update(inactivated_at: Time.now) if active?
    end

    def active?
      inactivated_at.nil?
    end

    def inactive?
      !active?
    end

    def to_activation
      I18n.t("active_regulation.activation.#{active? ? :active : :inactive}")
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_regulation-2.2.1 lib/active_regulation/activation.rb
active_regulation-2.2.0 lib/active_regulation/activation.rb
active_regulation-2.0.0 lib/active_regulation/activation.rb
active_regulation-1.0.1 lib/active_regulation/activation.rb
active_regulation-1.0.0 lib/active_regulation/activation.rb
active_regulation-0.1.0 lib/active_regulation/activation.rb