<commit_before>module Project::CustomValidators
  extend ActiveSupport::Concern

  included do
    @@routes = Rails.application.routes.routes
    validate :permalink_cant_be_route, allow_nil: true
    # This code might come back in a near future
    #validate :ensure_at_least_one_reward_validation, unless: :is_flexible?
    validate :validate_tags

    def validate_tags
      errors.add(:public_tags, :less_than_or_equal_to, count: 5) if public_tags.size > 5
    end

    def self.get_routes
      @@mapped_routes ||= @@routes.inject(Set.new) do |memo, item|
        memo << $1 if item.path.spec.to_s.match(/^\/([\w]+)\S/)
        memo
      end
    end

    def self.permalink_on_routes?(permalink)
      permalink && self.get_routes.include?(permalink.downcase)
    end

    def permalink_cant_be_route
      errors.add(:permalink, I18n.t("activerecord.errors.models.project.attributes.permalink.invalid")) if Project.permalink_on_routes?(permalink)
    end
    
    def ensure_at_least_one_reward_validation
      errors.add(
        'rewards.size',
        I18n.t("activerecord.errors.models.project.attributes.rewards.at_least_one")
      ) if rewards.empty?
    end
  end<commit_msg>allow_nil is not available on validate<commit_after>module Project::CustomValidators
  extend ActiveSupport::Concern

  included do
    @@routes = Rails.application.routes.routes
    validate :permalink_cant_be_route
    # This code might come back in a near future
    #validate :ensure_at_least_one_reward_validation, unless: :is_flexible?
    validate :validate_tags

    def validate_tags
      errors.add(:public_tags, :less_than_or_equal_to, count: 5) if public_tags.size > 5
    end

    def self.get_routes
      @@mapped_routes ||= @@routes.inject(Set.new) do |memo, item|
        memo << $1 if item.path.spec.to_s.match(/^\/([\w]+)\S/)
        memo
      end
    end

    def self.permalink_on_routes?(permalink)
      permalink && self.get_routes.include?(permalink.downcase)
    end

    def permalink_cant_be_route
      errors.add(:permalink, I18n.t("activerecord.errors.models.project.attributes.permalink.invalid")) if Project.permalink_on_routes?(permalink)
    end
    
    def ensure_at_least_one_reward_validation
      errors.add(
        'rewards.size',
        I18n.t("activerecord.errors.models.project.attributes.rewards.at_least_one")
      ) if rewards.empty?
    end
  end
{'fraction_non_alphanumeric': 0.10117056856187291, 'fraction_numerical': 0.005852842809364548, 'mean_word_length': 3.415129151291513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3624249', 'n_tokens_mistral': 830, 'n_tokens_neox': 811, 'n_words': 146}