<commit_before>class ImageUrlValidator < ActiveModel::Validator
  include HelperMethods

  IMAGE_HOST_WHITELIST = %w(bluemelon.com deviantart.com facebook.com flickr.com freeimagehosting.net imagebam.com imageshack.com imagevenue.com imgur.com instagram postimage.org photobucket.com picasa.com shutterfly.com slickpic.com snapfish.com smugmug.com tinypic.com twitpic.com webshots.com weheartit.com zenfolio.com)

  def validate(record)
     
    if record.image_url.present?  
      validates_format_of :image_url, :with => %r{\.(png|jpg|jpeg)$}i
      unless is_whitelisted?(record.image_url)
        record.errors[:image_url] = 'Invalid image url. Image provider not found in provider whitelist.'
      end
    end
  end

  private


  def is_whitelisted?(url)
    IMAGE_HOST_WHITELIST.any? {|whitelist_item| url.match /#{Regexp.escape(whitelist_item)}/ }
  end
end
<commit_msg>I think it's done now. All tests are passing<commit_after>class ImageUrlValidator < ActiveModel::Validator
  #include HelperMethods

  IMAGE_HOST_WHITELIST = %w(bluemelon.com deviantart.com facebook.com flickr.com freeimagehosting.net imagebam.com imageshack.com imagevenue.com imgur.com instagram postimage.org photobucket.com picasa.com shutterfly.com slickpic.com snapfish.com smugmug.com tinypic.com twitpic.com webshots.com weheartit.com zenfolio.com)

  def validate(record)
    validation_regex = %r{\.(png|jpg|jpeg)$}i
    if validation_regex.match(record.image_url) == nil
      record.errors[:image_url] = 'Invalid format. Image must be png, jpg, or jpeg.'
    end

    if record.image_url.present?
      unless is_whitelisted?(record.image_url) 
        record.errors[:image_url] = 'Invalid image url. Image provider not found in provider whitelist.'
      end
    end
  end

  private


  def is_whitelisted?(url)
    IMAGE_HOST_WHITELIST.any? {|whitelist_item| url.match /#{Regexp.escape(whitelist_item)}/ }
  end
end

{'fraction_non_alphanumeric': 0.09414225941422594, 'fraction_numerical': 0.0, 'mean_word_length': 4.241095890410959, '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': '7233036', 'n_tokens_mistral': 666, 'n_tokens_neox': 639, 'n_words': 142}