<commit_before>module PrereqValidations
  extend ActiveSupport::Concern

  included do
    validate :is_acyclic
  end

  def is_acyclic
    if self.send(self.class::PREREQ_MODEL) == self.prereq
      return errors.add(:base, "A self can't be a prerequisite to itself")
    end

    check_for_self = Proc.new do |current_self|
      if self.send(self.class::PREREQ_MODEL) == current_self
        return errors.add(:base, "Catch 22 detected. \"#{self.send(self.class::PREREQ_MODEL).title}\" is already required before \"#{self.prereq.title}\".")
      end

      current_self.prereqs.each do |self_to_check|
        check_for_self.call self_to_check
      end
    end

    check_for_self.call self.prereq
  end
end<commit_msg>simplified prereq validations<commit_after>module PrereqValidations
  extend ActiveSupport::Concern

  included do
    validate :is_acyclic
  end

  def is_acyclic
    return errors.add(:base, "A self can't be a prerequisite to itself") if self.send(self.class::PREREQ_MODEL) == self.prereq

    check_for_self = Proc.new do |current_self|
      return errors.add(:base, "Catch 22 detected. \"#{self.send(self.class::PREREQ_MODEL).title}\" is already required before \"#{self.prereq.title}\".") if self.send(self.class::PREREQ_MODEL) == current_self

      current_self.prereqs.each { |self_to_check| check_for_self.call(self_to_check) }
    end

    check_for_self.call self.prereq
  end
end
{'fraction_non_alphanumeric': 0.10734463276836158, 'fraction_numerical': 0.002824858757062147, 'mean_word_length': 3.8197278911564627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5204460', 'n_tokens_mistral': 510, 'n_tokens_neox': 473, 'n_words': 106}