<commit_before>require 'active_record'
require 'soft_deletion/version'
require 'soft_deletion/dependency'

module SoftDeletion
  def self.included(base)
    unless base.ancestors.include?(ActiveRecord::Base)
      raise "You can only include this if #{base} extends ActiveRecord::Base"
    end
    base.extend(ClassMethods)
    base.send(:default_scope, :conditions => base.soft_delete_default_scope_conditions)
    base.define_callbacks :after_soft_delete
  end

  module ClassMethods
    def soft_delete_default_scope_conditions
      {:deleted_at => nil}
    end

    def soft_delete_dependents
      self.reflect_on_all_associations.
        select { |a| [:destroy, :delete_all, :nullify].include?(a.options[:dependent]) }.
        map(&:name)
    end

    def with_deleted
      with_exclusive_scope do
        yield self
      end
    end
  end

  def deleted?
    deleted_at.present?
  end

  def mark_as_deleted!
    self.deleted_at = Time.now
  end

  def mark_as_undeleted!
    self.deleted_at = nil
  end

  def soft_delete!
    self.class.transaction do
      mark_as_deleted!
      soft_delete_dependencies.each(&:soft_delete!)
      save!
      run_callbacks(:after_soft_delete)
    end
  end

  def soft_undelete!
    self.class.transaction do
      mark_as_undeleted!
      soft_delete_dependencies.each(&:soft_undelete!)
      save!
    end
  end
<commit_msg>raname non-saving bang method<commit_after>require 'active_record'
require 'soft_deletion/version'
require 'soft_deletion/dependency'

module SoftDeletion
  def self.included(base)
    unless base.ancestors.include?(ActiveRecord::Base)
      raise "You can only include this if #{base} extends ActiveRecord::Base"
    end
    base.extend(ClassMethods)
    base.send(:default_scope, :conditions => base.soft_delete_default_scope_conditions)
    base.define_callbacks :after_soft_delete
  end

  module ClassMethods
    def soft_delete_default_scope_conditions
      {:deleted_at => nil}
    end

    def soft_delete_dependents
      self.reflect_on_all_associations.
        select { |a| [:destroy, :delete_all, :nullify].include?(a.options[:dependent]) }.
        map(&:name)
    end

    def with_deleted
      with_exclusive_scope do
        yield self
      end
    end
  end

  def deleted?
    deleted_at.present?
  end

  def mark_as_deleted
    self.deleted_at = Time.now
  end

  def mark_as_undeleted
    self.deleted_at = nil
  end

  def soft_delete!
    self.class.transaction do
      mark_as_deleted
      soft_delete_dependencies.each(&:soft_delete!)
      save!
      run_callbacks(:after_soft_delete)
    end
  end

  def soft_undelete!
    self.class.transaction do
      mark_as_undeleted
      soft_delete_dependencies.each(&:soft_undelete!)
      save!
    end
  end

{'fraction_non_alphanumeric': 0.07706222865412446, 'fraction_numerical': 0.0, 'mean_word_length': 3.2343032159264933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1736861', 'n_tokens_mistral': 903, 'n_tokens_neox': 884, 'n_words': 181}