<commit_before>module SmartApi
  class Responder
    def self.call(*args)
      new(*args).respond
    end

    def initialize(controller, resources, opts = {})
      @controller = controller
      @request    = @controller.request
      @resources  = resources.dup
      @resource   = @resources.pop
      @options    = opts
    end

    def respond
      case
      when @request.get?
        unless cache_fresh?
          if @resource.nil?
            @controller.render status: :not_found
            return
          end

          @controller.render
        end
      when @request.post?
        if @resource.nil?
          @controller.render status: :not_found
          return
        end

        if @resource.persisted?
          @controller.render status: :created
        else
          @controller.render status: :bad_request, json: { error: "Invalid attributes", attributes: @resource.errors }
        end
      when @request.put?
        if @resource.nil?
          @controller.render status: :not_found
          return
        end

        if @resource.persisted? && !@resource.changed?
          @controller.render status: :no_content
        else
          @controller.render status: :bad_request, json: { error: "Invalid attributes", attributes: @resource.errors }
        end
      when @request.delete?
        if @resource.nil?<commit_msg>204 No Content does not have content :)<commit_after>module SmartApi
  class Responder
    def self.call(*args)
      new(*args).respond
    end

    def initialize(controller, resources, opts = {})
      @controller = controller
      @request    = @controller.request
      @resources  = resources.dup
      @resource   = @resources.pop
      @options    = opts
    end

    def respond
      case
      when @request.get?
        unless cache_fresh?
          if @resource.nil?
            @controller.render status: :not_found
            return
          end

          @controller.render
        end
      when @request.post?
        if @resource.nil?
          @controller.render status: :not_found
          return
        end

        if @resource.persisted?
          @controller.render status: :created
        else
          @controller.render status: :bad_request, json: { error: "Invalid attributes", attributes: @resource.errors }
        end
      when @request.put?
        if @resource.nil?
          @controller.render status: :not_found
          return
        end

        if @resource.persisted? && !@resource.changed?
          @controller.head(:no_content)
        else
          @controller.render status: :bad_request, json: { error: "Invalid attributes", attributes: @resource.errors }
        end
      when @request.delete?
        if @resource.nil?
{'fraction_non_alphanumeric': 0.09011309740970448, 'fraction_numerical': 0.0010944910616563297, 'mean_word_length': 1.8924050632911393, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5599434', 'n_tokens_mistral': 723, 'n_tokens_neox': 708, 'n_words': 192}