<commit_before>class ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Token::ControllerMethods

  respond_to :json

  def resource_attributes
    params.require(:data).require(:attributes)
  end

  protected

  def authenticate!(options={})
    authenticate_token || render_error_for(:unauthorized)
  end

  def authenticate_token
    authenticate_with_http_token do |token, options|
      user = User.find_by(authentication_token: token)

      return false unless user

      sign_in(user, store: false)
    end
  end

  def check_parameters_for(root)
    if params['data'] &&
       params['data']['attributes'] &&
       params['data']['type'] == root.to_s.pluralize
      return
    end
    render_error_for(:bad_request)
  end

  def render_error_for(status)
    render json: { error: I18n.t("failure.#{status}") }, status: status
  end

  def render_validation_errors(model)
    errors = ValidationErrorsSerializer.serialize(model)

    render json: errors, status: :unprocessable_entity
  end
end<commit_msg>rename check_parameters_for root to resource_name<commit_after>class ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Token::ControllerMethods

  respond_to :json

  def resource_attributes
    params.require(:data).require(:attributes)
  end

  protected

  def authenticate!(options={})
    authenticate_token || render_error_for(:unauthorized)
  end

  def authenticate_token
    authenticate_with_http_token do |token, options|
      user = User.find_by(authentication_token: token)

      return false unless user

      sign_in(user, store: false)
    end
  end

  def check_parameters_for(resource_name)
    if params['data'] &&
       params['data']['attributes'] &&
       params['data']['type'] == resource_name.to_s.pluralize
      return
    end
    render_error_for(:bad_request)
  end

  def render_error_for(status)
    render json: { error: I18n.t("failure.#{status}") }, status: status
  end

  def render_validation_errors(model)
    errors = ValidationErrorsSerializer.serialize(model)

    render json: errors, status: :unprocessable_entity
  end
end
{'fraction_non_alphanumeric': 0.09558823529411764, 'fraction_numerical': 0.001838235294117647, 'mean_word_length': 4.348894348894349, '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': '3420706', 'n_tokens_mistral': 647, 'n_tokens_neox': 617, 'n_words': 135}