<commit_before># encoding: utf-8

module Hyperdrive
  class Response
    attr_reader :resource, :env, :http_request_method, :headers

    def initialize(env, resource)
      @resource = resource
      @env = env
      @http_request_method = env['REQUEST_METHOD']

      unless request_method_supported?
        raise Errors::NotImplemented.new(http_request_method)
      end

      unless resource.request_method_allowed?(http_request_method)
        raise Errors::MethodNotAllowed.new(http_request_method)
      end

      @headers = default_headers
    end

    def response
      @headers.merge({ 'Content-Type' => 'application/json' })
      status = (http_request_method == 'POST') ? 201 : 200
      ::Rack::Response.new(resource.request_handler(http_request_method).call(env, resource), status, headers).finish
    end

    private

    def default_headers
      {
        'Allow'        => resource.allowed_methods,
        'Content-Type' => 'application/json'
      }
    end

    def request_method_supported?
      Hyperdrive::Values.request_methods_string_map.key?(http_request_method)
    end
  end
end<commit_msg>use new method names and get resource from env<commit_after># encoding: utf-8

module Hyperdrive
  class Response
    attr_reader :resource, :env, :http_request_method, :headers

    def initialize(env)
      @env = env
      @resource = env['hyperdrive.resource']
      @http_request_method = env['REQUEST_METHOD']

      unless request_method_supported?
        raise Errors::NotImplemented.new(http_request_method)
      end

      unless resource.request_method_allowed?(http_request_method)
        raise Errors::MethodNotAllowed.new(http_request_method)
      end

      @headers = default_headers
    end

    def response
      @headers.merge({ 'Content-Type' => 'application/json' })
      status = (http_request_method == 'POST') ? 201 : 200
      ::Rack::Response.new(resource.request_handler(http_request_method).call(env), status, headers).finish
    end

    private

    def default_headers
      {
        'Allow'        => resource.allowed_methods,
        'Content-Type' => 'application/json'
      }
    end

    def request_method_supported?
      Hyperdrive::Values.http_request_methods.key?(http_request_method)
    end
  end
end
{'fraction_non_alphanumeric': 0.09530083443126922, 'fraction_numerical': 0.006148440931049627, 'mean_word_length': 3.1875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1750654', 'n_tokens_mistral': 679, 'n_tokens_neox': 652, 'n_words': 131}