<commit_before>module Travis::API::V3
  class Queries::KeyPair < Query
    params :description, :value, prefix: :key_pair

    def find(repository)
      repository.key_pair or raise EntityMissing.new(:key_pair)
    end

    def create(repository)
      raise DuplicateResource if find(repository)
      Models::KeyPair.new(key_pair_params.merge(repository_id: repository.id)).tap do |key_pair|
        handle_errors(key_pair) unless key_pair.valid?
        key_pair.sync_once(repository, :settings)
      end
    end

    def update(repository)
      key_pair = find(repository)
      key_pair.update(key_pair_params) or handle_errors(key_pair)
    end

    def delete(repository)
      key_pair = find(repository)
      key_pair.delete(repository)
    end

    private

    def handle_errors(key_pair)
      value = key_pair.errors[:value]
      raise UnprocessableEntity if value.include?(:invalid_pem)
      raise WrongParams         if value.include?(:missing_attr)
    end
  end
end<commit_msg>No need for find in this query<commit_after>module Travis::API::V3
  class Queries::KeyPair < Query
    params :description, :value, prefix: :key_pair

    def find(repository)
      repository.key_pair or raise EntityMissing.new(:key_pair)
    end

    def create(repository)
      raise DuplicateResource if repository.key_pair
      Models::KeyPair.new(key_pair_params.merge(repository_id: repository.id)).tap do |key_pair|
        handle_errors(key_pair) unless key_pair.valid?
        key_pair.sync_once(repository, :settings)
      end
    end

    def update(repository)
      key_pair = find(repository)
      key_pair.update(key_pair_params) or handle_errors(key_pair)
    end

    def delete(repository)
      key_pair = find(repository)
      key_pair.delete(repository)
    end

    private

    def handle_errors(key_pair)
      value = key_pair.errors[:value]
      raise UnprocessableEntity if value.include?(:invalid_pem)
      raise WrongParams         if value.include?(:missing_attr)
    end
  end
end
{'fraction_non_alphanumeric': 0.08267326732673268, 'fraction_numerical': 0.0009900990099009901, 'mean_word_length': 3.355603448275862, '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': '7541837', 'n_tokens_mistral': 622, 'n_tokens_neox': 601, 'n_words': 133}