<commit_before>class Router
  def initialize(request)
    @request = request
  end


  def process!
    if klass = controller
      @request.params.merge!(path_info)

      ctrl = klass.new(@request)
      method = action

      if ctrl.respond_to?(method)
        return ctrl.public_send(method)
      end
    end

    not_found
  end


  def controller_name
    "#{path_info[:group].capitalize}Controller"
  end


  def controller
    Object.const_get(controller_name)
  rescue NameError
    nil
  end


  def action
    if path_info[:action]
      path_info[:action].to_sym
    else
      if path_info[:id]
        :show
      else
        :index
      end
    end
  end


  def path_info
    @path_info ||= {
      group: path_components[0],
      id: path_components[1],
      action: path_components[2]
    }
  end


  def path_components
    @comps ||= @request.path.split("/").reject { |s| s.empty? }
  end


  def not_found(msg = "Not Found")
    [404, {}, [msg]]
  end
end<commit_msg>the router understand GET new and POST create<commit_after>class Router
  def initialize(request)
    @request = request
  end


  def process!
    if klass = controller
      @request.params.merge!(path_info)

      ctrl = klass.new(@request)
      method = action

      if ctrl.respond_to?(method)
        puts "\nRouting to #{controller}##{method}"
        return ctrl.public_send(method)
      end
    end

    not_found
  end


  def controller_name
    "#{path_info[:group].capitalize}Controller"
  end


  def controller
    Object.const_get(controller_name)
  rescue NameError
    nil
  end


  def action
    if path_info[:action]
      path_info[:action].to_sym
    else
      if path_info[:id]
        :show
      else
        @request.get? ? :index : :create
      end
    end
  end


  def path_info
    @path_info ||= begin
      info = {
        group: path_components[0],
        id: path_components[1],
        action: path_components[2]
      }

      if info[:id] == 'new'
        info[:action] = info.delete(:id)
      end
      info
    end
  end


  def path_components
    @comps ||= @request.path.split("/").reject { |s| s.empty? }
  end


  def not_found(msg = "Not Found")
    [404, {}, [msg]]
  end
end
{'fraction_non_alphanumeric': 0.1052158273381295, 'fraction_numerical': 0.00539568345323741, 'mean_word_length': 2.2293178519593613, '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': '2915621', 'n_tokens_mistral': 753, 'n_tokens_neox': 722, 'n_words': 172}