Sha256: dc0009a5c912fc42b9991d3c214074c0b9472824daea23bf3abbd2cf6ef313b0

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

$:.push File.expand_path('../', __FILE__)
require "active_support/all"
require "archiveable/version"

module Archiveable
  extend ActiveSupport::Concern

  included do
    scope :published, -> { where archived_at: nil }
    scope :archived, -> { where.not archived_at: nil }
  end

  def published
    !archived
  end

  def published=(value)
    self.archived = !bool(value)
  end

  def archived
    archived_at.present?
  end

  def archived=(value)
    self.archived_at = bool(value) ? Time.now : nil
  end

  def archive
    update archived: true
  end

  def archive!
    update! archived: true
  end

  def publish
    update archived: false
  end

  def publish!
    update! archived: false
  end

  private

  def bool(value)
    not ["false", "0", ""].include? value.to_s.downcase
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
archiveable-0.0.6 lib/archiveable.rb