<commit_before>module Crops
  # Place shared functionality between Stage mutations here to stay DRY.
  module CropsConcern
    def validate_images
      images && images.each do |pic|
        if pic[:id]
          exist_pic = @existing_crop.pictures.find(pic[:id])
          unless exist_pic.attachment.url == pic[:image_url]
            add_error :images,
                      :changed_image, 'You can\'t change an existing image, '\
                      'delete it and upload an other image.'
          end
        elsif not pic[:image_url].valid_url?
          add_error :images,
                    :invalid_url, "'#{pic[:image_url]}' is not a valid URL. "\
                    'Ensure that it is a fully formed URL (including HTTP://'\
                    ' or HTTPS://)'
        end
      end
    end

    def set_pictures
      existing_pics = []
      images && images.map do |pic|
        if pic[:id]
          # Find the pictures with a given ID
          existing_pics.push(@existing_crop.pictures.find(pic[:id])._id)
        else
          existing_pics.push(Picture.from_url(pic[:image_url],
                                              @existing_crop)._id)
        end
      end
      @existing_crop.pictures.each do |pic|
        unless existing_pics.include? pic[:id]
          pic.remove()
        end
      end
    end
  end
end<commit_msg>Made if statement comply to ruby style guide<commit_after>module Crops
  # Place shared functionality between Stage mutations here to stay DRY.
  module CropsConcern
    def validate_images
      images && images.each do |pic|
        if pic[:id]
          exist_pic = @existing_crop.pictures.find(pic[:id])
          unless exist_pic.attachment.url == pic[:image_url]
            add_error :images,
                      :changed_image, 'You can\'t change an existing image, '\
                      'delete it and upload an other image.'
          end
        else
          unless pic[:image_url].valid_url?
            add_error :images,
                      :invalid_url, "'#{pic[:image_url]}' is not a valid URL. "\
                      'Ensure that it is a fully formed URL (including HTTP://'\
                      ' or HTTPS://)'
          end
        end
      end
    end

    def set_pictures
      existing_pics = []
      images && images.map do |pic|
        if pic[:id]
          # Find the pictures with a given ID
          existing_pics.push(@existing_crop.pictures.find(pic[:id])._id)
        else
          existing_pics.push(Picture.from_url(pic[:image_url],
                                              @existing_crop)._id)
        end
      end
      @existing_crop.pictures.each do |pic|
        unless existing_pics.include? pic[:id]
          pic.remove()
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08970218873340509, 'fraction_numerical': 0.0, 'mean_word_length': 1.6129334582942831, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3501393', 'n_tokens_mistral': 788, 'n_tokens_neox': 765, 'n_words': 217}