<commit_before>module ApiControllerHelpers

  module Helpers

    def render_action_outcome(record)
      if record.valid?
        render_record(record)
      else
        render_errors(record.errors)
      end
    end

    def render_record(record)
      render json: {self.class.record_json_key => record}
    end

    def render_errors(errors)
      render json: {errors: errors}, status: :conflict
    end

    def render_collection(collection)
      render json: {self.class.collection_json_key => collection}
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def record_json_key
        @record_json_key ||= name.chomp('Controller').underscore.singularize
      end

      def collection_json_key
        @collection_json_key ||= name.chomp('Controller').underscore
      end
    end

  end

end
<commit_msg>Standardize returned JSON to use "data" key, i.e. {data: result}<commit_after>module ApiControllerHelpers

  module Helpers

    def render_action_outcome(record)
      if record.valid?
        render_record(record)
      else
        render_errors(record.errors)
      end
    end

    def render_record(record)
      render json: wrap_result(record)
    end

    def render_errors(errors)
      render json: wrap_result(errors: errors), status: :conflict
    end

    def render_collection(collection)
      render json: wrap_result(collection)
    end

    def wrap_result(result)
      {data: result}
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      # add class methods here
    end

  end

end

{'fraction_non_alphanumeric': 0.07177914110429448, 'fraction_numerical': 0.0, 'mean_word_length': 2.6984126984126986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1350837', 'n_tokens_mistral': 493, 'n_tokens_neox': 472, 'n_words': 116}