<commit_before>module Ohm
  # Provides support for soft deletion
  #
  # @example
  #
  #   class Post < Ohm::Model
  #     plugin :softdelete
  #
  #     attribute :title
  #     index :title
  #   end
  #
  #   post = Post.create(:title => 'Title')
  #
  #   post.deleted?
  #   # => false
  #
  #   post.delete
  #
  #   post.deleted?
  #   # => true
  #
  #   Post.all.empty?
  #   # => true
  #
  #   Post.find(:title => 'Title').include?(post)
  #   # => true
  #
  #   Post.exists?(post.id)
  #   # => true
  #
  #   post = Post[post.id]
  #
  #   post.deleted?
  #   # => true
  module SoftDelete
    DELETED_FLAG = "1"

    def self.included(model)
      model.attribute :deleted

      model.extend ClassMethods
    end

    def delete
      self.deleted = DELETED_FLAG

      redis.queue("MULTI")
      redis.queue("SREM", model.all.key, id)
      redis.queue("SADD", model.deleted.key, id)
      redis.queue("HSET", key, :deleted, deleted)
      redis.queue("EXEC")
      redis.commit

      self
    end

    def restore
      self.deleted = nil

      redis.queue("MULTI")
      redis.queue("SADD", model.all.key, id)
      redis.queue("SREM", model.deleted.key, id)
      redis.queue("HSET", key, :deleted, deleted)<commit_msg>Update Ohm::SoftDelete documentation.<commit_after>module Ohm
  # Provides support for soft deletion.
  #
  #   class Post < Ohm::Model
  #     include Ohm::SoftDelete
  #
  #     attribute :title
  #     index :title
  #   end
  #
  #   post = Post.create(title: 'Title')
  #
  #   post.deleted?
  #   # => false
  #
  #   post.delete
  #
  #   post.deleted?
  #   # => true
  #
  #   Post.all.empty?
  #   # => true
  #
  #   Post.find(title: 'Title').include?(post)
  #   # => true
  #
  #   Post.exists?(post.id)
  #   # => true
  #
  #   post = Post[post.id]
  #
  #   post.deleted?
  #   # => true
  #
  module SoftDelete
    DELETED_FLAG = "1"

    def self.included(model)
      model.attribute :deleted

      model.extend ClassMethods
    end

    def delete
      self.deleted = DELETED_FLAG

      redis.queue("MULTI")
      redis.queue("SREM", model.all.key, id)
      redis.queue("SADD", model.deleted.key, id)
      redis.queue("HSET", key, :deleted, deleted)
      redis.queue("EXEC")
      redis.commit

      self
    end

    def restore
      self.deleted = nil

      redis.queue("MULTI")
      redis.queue("SADD", model.all.key, id)
      redis.queue("SREM", model.deleted.key, id)
      redis.queue("HSET", key, :deleted, deleted)
{'fraction_non_alphanumeric': 0.14789579158316632, 'fraction_numerical': 0.0008016032064128256, 'mean_word_length': 2.0701107011070112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1640562', 'n_tokens_mistral': 933, 'n_tokens_neox': 933, 'n_words': 164}