<commit_before>class WhitelistedHost < ActiveRecord::Base
  has_paper_trail

  before_save :ensure_papertrail_user_config

  validates :hostname, presence: true
  validates :hostname, hostname: true
  validates :hostname, uniqueness: { message: 'is already in the list' }
  validate :hostname_is_not_automatically_allowed_anyway

  def ensure_papertrail_user_config
    Transition::History.ensure_user!
  end

  def hostname_is_not_automatically_allowed_anyway
    return if hostname.nil?
    if hostname.end_with?('.gov.uk') || hostname.end_with?('.mod.uk')
      errors.add(:hostname, 'cannot end in .gov.uk or .mod.uk - these are automatically whitelisted')
    end<commit_msg>Lowercase any host added to the whitelist<commit_after>class WhitelistedHost < ActiveRecord::Base
  has_paper_trail

  before_save :ensure_papertrail_user_config

  before_validation { hostname.try(:downcase!) }
  validates :hostname, presence: true
  validates :hostname, hostname: true
  validates :hostname, uniqueness: { message: 'is already in the list' }
  validate :hostname_is_not_automatically_allowed_anyway

  def ensure_papertrail_user_config
    Transition::History.ensure_user!
  end

  def hostname_is_not_automatically_allowed_anyway
    return if hostname.nil?
    if hostname.end_with?('.gov.uk') || hostname.end_with?('.mod.uk')
      errors.add(:hostname, 'cannot end in .gov.uk or .mod.uk - these are automatically whitelisted')
    end
{'fraction_non_alphanumeric': 0.08559498956158663, 'fraction_numerical': 0.0, 'mean_word_length': 5.093220338983051, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4600835', 'n_tokens_mistral': 459, 'n_tokens_neox': 453, 'n_words': 107}