Files
danbooru/app/logical/concerns/deletable.rb
evazion a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00

29 lines
641 B
Ruby

# frozen_string_literal: true
# A concern that adds common helper methods to models that are soft deletable.
#
# @example
# class Post
# deletable
# end
#
module Deletable
extend ActiveSupport::Concern
class_methods do
def deletable
scope :active, -> { where(is_deleted: false) }
scope :deleted, -> { where(is_deleted: true) }
scope :undeleted, -> { where(is_deleted: false) }
define_method(:soft_delete) do |**options|
update(is_deleted: true, **options)
end
define_method(:soft_delete!) do |**options|
update!(is_deleted: true, **options)
end
end
end
end