<commit_before>module Cangaroo
  class Connection < ActiveRecord::Base
    serialize :parameters

    validates :name, :url, :key, :token, presence: true
    validates :name, :url, :key, :token, uniqueness: true

    after_initialize :set_default_parameters

    def self.authenticate(key, token)
      where(key: key, token: token).first
    end

    private

      def set_default_parameters
        self.parameters ||= {}
      end
  end
end<commit_msg>Conditionally check for token presence and uniqueness on `basic_auth`<commit_after>module Cangaroo
  class Connection < ActiveRecord::Base
    serialize :parameters

    validates :name, :url, :key, presence: true, uniqueness: true
    validates :token, presence: true, uniqueness: true, if: -> { !Rails.configuration.cangaroo.basic_auth }

    after_initialize :set_default_parameters

    def self.authenticate(key, token)
      where(key: key, token: token).first
    end

    private

      def set_default_parameters
        self.parameters ||= {}
      end
  end
end
{'fraction_non_alphanumeric': 0.08949416342412451, 'fraction_numerical': 0.0, 'mean_word_length': 3.473913043478261, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '4870961', 'n_tokens_mistral': 310, 'n_tokens_neox': 291, 'n_words': 85}