<commit_before>require 'rack/request'

autoload :JSON, 'json'
autoload :YAML, 'yaml'

module Ww::Double::Spy
  class Request < ::Rack::Request
    attr_reader :time
    @@req_parsers = []

    def self.regist_request_parser(pattern, &block)
      @@req_parsers << [pattern, block]
    end

    regist_request_parser %r{[application|text]/json} do |body|
      JSON.parse(body)
    end

    regist_request_parser %r{[application|text]/json} do |body|
      JSON.parse(body)
    end

    regist_request_parser %r{[application|text]/yaml} do |body|
      YAML.load(body)
    end

    def initialize(req_or_env)<commit_msg>remove dependencies to JSON gem.<commit_after>require 'rack/request'

autoload :JSON, 'json'
autoload :YAML, 'yaml'

module Ww::Double::Spy
  if defined?(ActiveSupport::JSON)
    def decode_json(json_string)
      ActiveSupport::JSON.decode(json_string)
    end
  else
    unless defined?(::JSON)
      begin
        require 'json_pure'
      rescue LoadError
        require 'json'
      end
    end
    def decode_json(json_string)
      ::JSON.parse(json_string)
    end
  end

  module_function :decode_json

  class Request < ::Rack::Request
    attr_reader :time
    @@req_parsers = []

    def self.regist_request_parser(pattern, &block)
      @@req_parsers << [pattern, block]
    end

    regist_request_parser %r{[application|text]/json} do |body|
      ::Ww::Double::Spy.decode_json(body)
    end

    regist_request_parser %r{[application|text]/json} do |body|
      ::Ww::Double::Spy.decode_json(body)
    end

    regist_request_parser %r{[application|text]/yaml} do |body|
      YAML.load(body)
    end

    def initialize(req_or_env)
{'fraction_non_alphanumeric': 0.11990407673860912, 'fraction_numerical': 0.0, 'mean_word_length': 3.4506666666666668, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5258983', 'n_tokens_mistral': 591, 'n_tokens_neox': 563, 'n_words': 114}