<commit_before>module Gitorious
  module RepositoryRoutes
    class CustomPrefixResource < ActionDispatch::Routing::Mapper::Resource
      attr_accessor :prefix

      def member_scope
        ["#{prefix}:id", options]
      end

      def nested_path
        "#{prefix}:#{singular}_id"
      end
    end

    def resources_with_custom_prefix(name, prefix = nil, options = {}, &block)
      if @scope[:scope_level] == :resources
        nested do
          resources_with_custom_prefix(name, nil, options, &block)
        end
        return
      end

      resource = CustomPrefixResource.new(name, options)
      resource.prefix = prefix
      resource_scope(resource) do
        yield if block_given?

        #collection_scope do
        #  get  :index if parent_resource.actions.include?(:index)
        #  post :create if parent_resource.actions.include?(:create)
        #end

        # new_scope do
        #   get :new
        # end if parent_resource.actions.include?(:new)
        # 
        # member_scope do
        #   get    :show if parent_resource.actions.include?(:show)
        #   put    :update if parent_resource.actions.include?(:update)
        #   delete :destroy if parent_resource.actions.include?(:destroy)
        #   get    :edit if parent_resource.actions.include?(:edit)
        # end
      end
    end

    def repositories
      resources_with_custom_prefix :repositories do
        member do
          get :clone
          post :create_clone
          get :writable_by
          get :config
          get :confirm_delete
          get :committers
          get :search_clones

          match "trees" => "trees#index", :as => :trees
          match "trees/*branch_and_path" => "trees#show", :as => :tree
          match "trees/*branch_and_path.:format" => "trees#show", :as => :formatted_tree
          match "archive-tarball/*branch" => "trees#archive", :as => :archive_tar, :defaults => {:archive_forat => "tar.gz"}
          match "archive-zip/*branch" => "trees#archive", :as => :archive_zip, :defaults => {:archive_format => "zip"}
        end

        # Make some of these member-ish routes act as if they were on a
        # nested controller, causing :repository_id instead of :id.
        with_scope_level :member do
          scope ":repository_id", :name_prefix => parent_resource.member_name, :as => "" do
            match "comments/commit/:sha" => "comments#commit", :as => :commit_comment, :via => :get
            match "comments/preview" => "comments#preview", :as => :comments_preview

            # #   repo.formatted_commits_feed "commits/*branch/feed.:format",
            # #       :controller => "commits", :action => "feed", :conditions => {:feed => :get}
            match "commits/*branch/feed.:format" => "commits#feed", :as => :formatted_commits_feed
            match "commits" => "commits#index", :as => :commits
            match "commits/*branch" => "commits#index", :as => :commits_in_ref<commit_msg>Trying to rename the old config route<commit_after>module Gitorious
  module RepositoryRoutes
    class CustomPrefixResource < ActionDispatch::Routing::Mapper::Resource
      attr_accessor :prefix

      def member_scope
        ["#{prefix}:id", options]
      end

      def nested_path
        "#{prefix}:#{singular}_id"
      end
    end

    def resources_with_custom_prefix(name, prefix = nil, options = {}, &block)
      if @scope[:scope_level] == :resources
        nested do
          resources_with_custom_prefix(name, nil, options, &block)
        end
        return
      end

      resource = CustomPrefixResource.new(name, options)
      resource.prefix = prefix
      resource_scope(resource) do
        yield if block_given?

        #collection_scope do
        #  get  :index if parent_resource.actions.include?(:index)
        #  post :create if parent_resource.actions.include?(:create)
        #end

        # new_scope do
        #   get :new
        # end if parent_resource.actions.include?(:new)
        # 
        # member_scope do
        #   get    :show if parent_resource.actions.include?(:show)
        #   put    :update if parent_resource.actions.include?(:update)
        #   delete :destroy if parent_resource.actions.include?(:destroy)
        #   get    :edit if parent_resource.actions.include?(:edit)
        # end
      end
    end

    def repositories
      resources_with_custom_prefix :repositories do
        member do
          get :clone
          post :create_clone
          get :writable_by
          get :configure
          get :confirm_delete
          get :committers
          get :search_clones

          match "trees" => "trees#index", :as => :trees
          match "trees/*branch_and_path" => "trees#show", :as => :tree
          match "trees/*branch_and_path.:format" => "trees#show", :as => :formatted_tree
          match "archive-tarball/*branch" => "trees#archive", :as => :archive_tar, :defaults => {:archive_forat => "tar.gz"}
          match "archive-zip/*branch" => "trees#archive", :as => :archive_zip, :defaults => {:archive_format => "zip"}
        end

        # Make some of these member-ish routes act as if they were on a
        # nested controller, causing :repository_id instead of :id.
        with_scope_level :member do
          scope ":repository_id", :name_prefix => parent_resource.member_name, :as => "" do
            match "comments/commit/:sha" => "comments#commit", :as => :commit_comment, :via => :get
            match "comments/preview" => "comments#preview", :as => :comments_preview

            # #   repo.formatted_commits_feed "commits/*branch/feed.:format",
            # #       :controller => "commits", :action => "feed", :conditions => {:feed => :get}
            match "commits/*branch/feed.:format" => "commits#feed", :as => :formatted_commits_feed
            match "commits" => "commits#index", :as => :commits
            match "commits/*branch" => "commits#index", :as => :commits_in_ref
{'fraction_non_alphanumeric': 0.12074459164849907, 'fraction_numerical': 0.0, 'mean_word_length': 2.465427077280651, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 65, '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': '1538005', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1675, 'n_words': 413}