<commit_before>module Apipie
  module Extractor
    class Recorder
      MULTIPART_BOUNDARY = 'APIPIE_RECORDER_EXAMPLE_BOUNDARY'

      def initialize
        @ignored_params = [:controller, :action]
      end

      def analyse_env(env)
        @verb = env["REQUEST_METHOD"].to_sym
        @path = env["PATH_INFO"].sub(/^\/*/,"/")
        @query = env["QUERY_STRING"] unless env["QUERY_STRING"].blank?
        @params = Rack::Utils.parse_nested_query(@query)
        @params.merge!(env["action_dispatch.request.request_parameters"] || {})
        if data = parse_data(env["rack.input"].read)
          @request_data = data
          env["rack.input"].rewind
        elsif form_hash = env["rack.request.form_hash"]
          @request_data = reformat_multipart_data(form_hash)
        end
      end

      def analyse_controller(controller)
        @controller = controller.class
        @action = controller.params[:action]
      end

      def analyse_response(response)
        if response.last.respond_to?(:body) && data = parse_data(response.last.body)
          @response_data = data
        end
        @code = response.first
      end

      def analyze_functional_test(test_context)
        request, response = test_context.request, test_context.response
        @verb = request.request_method.to_sym
        @path = request.path
        @params = request.request_parameters
        if [:POST, :PUT, :PATCH].include?(@verb)
          @request_data = @params
        else
          @query = request.query_string
        end
        @response_data = parse_data(response.body)
        @code = response.code
      end

      def parse_data(data)
        return nil if data.strip.blank?
        JSON.parse(data)
      rescue StandardError
        data
      end

      def reformat_multipart_data(form)
        form.empty? and return ''
        lines = ["Content-Type: multipart/form-data; boundary=#{MULTIPART_BOUNDARY}",'']
        boundary = "--#{MULTIPART_BOUNDARY}"
        form.each do |key, attrs|
          if attrs.is_a?(String)
            lines << boundary << content_disposition(key) << "Content-Length: #{attrs.size}" << '' << attrs
          else
            reformat_hash(boundary, attrs, lines)
          end
        end
        lines << "#{boundary}--"
        lines.join("\n")
      end
<commit_msg>Include delete request parmeters in generated documentation<commit_after>module Apipie
  module Extractor
    class Recorder
      MULTIPART_BOUNDARY = 'APIPIE_RECORDER_EXAMPLE_BOUNDARY'

      def initialize
        @ignored_params = [:controller, :action]
      end

      def analyse_env(env)
        @verb = env["REQUEST_METHOD"].to_sym
        @path = env["PATH_INFO"].sub(/^\/*/,"/")
        @query = env["QUERY_STRING"] unless env["QUERY_STRING"].blank?
        @params = Rack::Utils.parse_nested_query(@query)
        @params.merge!(env["action_dispatch.request.request_parameters"] || {})
        if data = parse_data(env["rack.input"].read)
          @request_data = data
          env["rack.input"].rewind
        elsif form_hash = env["rack.request.form_hash"]
          @request_data = reformat_multipart_data(form_hash)
        end
      end

      def analyse_controller(controller)
        @controller = controller.class
        @action = controller.params[:action]
      end

      def analyse_response(response)
        if response.last.respond_to?(:body) && data = parse_data(response.last.body)
          @response_data = data
        end
        @code = response.first
      end

      def analyze_functional_test(test_context)
        request, response = test_context.request, test_context.response
        @verb = request.request_method.to_sym
        @path = request.path
        @params = request.request_parameters
        if [:POST, :PUT, :PATCH, :DELETE].include?(@verb)
          @request_data = @params
        else
          @query = request.query_string
        end
        @response_data = parse_data(response.body)
        @code = response.code
      end

      def parse_data(data)
        return nil if data.strip.blank?
        JSON.parse(data)
      rescue StandardError
        data
      end

      def reformat_multipart_data(form)
        form.empty? and return ''
        lines = ["Content-Type: multipart/form-data; boundary=#{MULTIPART_BOUNDARY}",'']
        boundary = "--#{MULTIPART_BOUNDARY}"
        form.each do |key, attrs|
          if attrs.is_a?(String)
            lines << boundary << content_disposition(key) << "Content-Length: #{attrs.size}" << '' << attrs
          else
            reformat_hash(boundary, attrs, lines)
          end
        end
        lines << "#{boundary}--"
        lines.join("\n")
      end

{'fraction_non_alphanumeric': 0.11373801916932907, 'fraction_numerical': 0.0, 'mean_word_length': 2.3117066290550072, 'pattern_counts': {'":': 0, '<': 27, '<?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': '796991', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1363, 'n_words': 267}