Nwht0xn1

WikiHubのroutes.rbCreated on 2016-05-08 by r7kamura

WikiHubの2016年5月8日時点でのconfig/routes.rbの様子。

ルール

以下のルールを元に書いている。

  • resourcesを利用しない
  • URLとHTTPメソッドで辞書順にソート
  • 同じブロック内でハッシュロケットの水平位置を揃える

全体観

以下の3種類のパートに分かれている。

  1. ドメインに関係なく利用するエンドポイント
  2. サブドメインを利用しないエンドポイント
  3. サブドメインを利用するエンドポイント

コード

以下が実際のコード (そのまま)。

Rails.application.routes.draw do
  post   "/feedback"              => "feedback_records#create", as: :feedback
  get    "/login"                 => "sessions#new", as: :log_in
  post   "/login"                 => "sessions#create"
  delete "/logout"                => "sessions#destroy", as: :log_out
  get    "/recovery_code_session" => "recovery_code_sessions#new", as: :recovery_code_session
  post   "/recovery_code_session" => "recovery_code_sessions#create"
  get    "/two_factor_session"    => "two_factor_sessions#new", as: :two_factor_session
  post   "/two_factor_session"    => "two_factor_sessions#create"

  constraints subdomain: /\A\z/ do
    root   "top_pages#show"
    get    "/about"                                   => "abouts#show", as: :about
    get    "/api/v1/users/:user_name"                 => "api/v1/users#show"
    get    "/articles"                                => "public_articles#index", as: :public_articles
    get    "/auth/github/callback"                    => "github_oauth_callbacks#show", as: :github_oauth_callback
    get    "/auth/twitter/callback"                   => "twitter_oauth_callbacks#show", as: :twitter_oauth_callback
    get    "/communities"                             => "communities#index", as: :communities
    get    "/notifications"                           => "notifications#index", as: :notifications
    get    "/notifications/:notification_id"          => "notifications#show", as: :notification
    get    "/participating"                           => "participating_communities#index", as: :participating_communities
    get    "/password_reset"                          => "password_reset_tokens#new", as: :new_password_reset_token
    post   "/password_reset"                          => "password_reset_tokens#create", as: :password_reset_tokens
    delete "/password_reset/:password_reset_token"    => "password_reset_tokens#destroy", as: :password_reset_token
    get    "/password_reset/:password_reset_token"    => "password_reset_tokens#show"
    get    "/settings/account"                        => "accounts#show", as: :account
    patch  "/settings/account"                        => "accounts#update"
    delete "/settings/github_oauth_authorization"     => "github_oauth_authorizations#destroy", as: :github_oauth_authorization
    post   "/settings/github_oauth_authorization"     => "github_oauth_authorizations#create"
    get    "/settings/profile"                        => "profiles#show", as: :profile
    patch  "/settings/profile"                        => "profiles#update"
    get    "/settings/recovery_codes"                 => "recovery_codes#index", as: :recovery_codes
    post   "/settings/recovery_codes"                 => "recovery_codes#create"
    get    "/settings/security"                       => "securities#show", as: :security
    get    "/settings/tokens"                         => "personal_access_tokens#index", as: :personal_access_tokens
    post   "/settings/tokens"                         => "personal_access_tokens#create"
    get    "/settings/tokens/new"                     => "personal_access_tokens#new", as: :new_personal_access_token
    delete "/settings/tokens/:oauth_access_token_id"  => "personal_access_tokens#destroy", as: :personal_access_token
    get    "/settings/tokens/:oauth_access_token_id"  => "personal_access_tokens#show"
    patch  "/settings/tokens/:oauth_access_token_id"  => "personal_access_tokens#update"
    delete "/settings/twitter_oauth_authorization"    => "twitter_oauth_authorizations#destroy", as: :twitter_oauth_authorization
    post   "/settings/twitter_oauth_authorization"    => "twitter_oauth_authorizations#create"
    delete "/settings/two_factor_authentication"      => "two_factor_authentications#destroy", as: :two_factor_authentication
    post   "/settings/two_factor_authentication"      => "two_factor_authentications#create", as: :two_factor_authentications
    get    "/settings/two_factor_authentication/new"  => "two_factor_authentications#new", as: :new_two_factor_authentication
    get    "/sign_up"                                 => "users#new", as: :sign_up
    post   "/sign_up"                                 => "users#create"
    get    "/stars"                                   => "starred_communities#index", as: :starred_communities
    delete "/user_sessions/:user_session_id"          => "user_sessions#destroy", as: :user_session
    get    "/@:user_name"                             => "users#show", as: :user
    get    "/@:user_name/followees"                   => "user_followees#index", as: :user_followees
    get    "/@:user_name/followers"                   => "user_followers#index", as: :user_followers
    delete "/@:user_name/following"                   => "user_followings#destroy", as: :user_following
    post   "/@:user_name/following"                   => "user_followings#create"
  end

  constraints subdomain: /\A.+\z/ do
    delete "/"                                                               => "communities#destroy", as: :community
    get    "/"                                                               => "communities#show"
    post   "/api/internal/preview"                                           => "api/internal/previews#create", as: :api_internal_preview
    get    "/api/v1/articles"                                                => "api/v1/articles#index"
    post   "/api/v1/articles"                                                => "api/v1/articles#create"
    get    "/api/v1/issues"                                                  => "api/v1/issues#index"
    post   "/api/v1/issues"                                                  => "api/v1/issues#create"
    get    "/api/v1/issues/:issue_incremental_id"                            => "api/v1/issues#show"
    patch  "/api/v1/issues/:issue_incremental_id"                            => "api/v1/issues#update"
    get    "/api/v1/issues/:issue_incremental_id/comments"                   => "api/v1/issue_comments#index"
    post   "/api/v1/issues/:issue_incremental_id/comments"                   => "api/v1/issue_comments#create"
    delete "/api/v1/issues/:issue_incremental_id/comments/:issue_comment_id" => "api/v1/issue_comments#destroy"
    get    "/api/v1/issues/:issue_incremental_id/comments/:issue_comment_id" => "api/v1/issue_comments#show"
    patch  "/api/v1/issues/:issue_incremental_id/comments/:issue_comment_id" => "api/v1/issue_comments#update"
    get    "/api/v1/pages"                                                   => "api/v1/pages#index"
    post   "/api/v1/pages"                                                   => "api/v1/pages#create"
    delete "/api/v1/pages/*page_title"                                       => "api/v1/pages#destroy", format: false
    get    "/api/v1/pages/*page_title"                                       => "api/v1/pages#show", format: false
    patch  "/api/v1/pages/*page_title"                                       => "api/v1/pages#update", format: false
    get    "/api/v1/user_memberships"                                        => "api/v1/user_memberships#index"
    get    "/api/v1/users/:user_name/articles"                               => "api/v1/user_articles#show"
    delete "/api/v1/users/:user_name/articles/:article_timestamp_id"         => "api/v1/articles#destroy"
    get    "/api/v1/users/:user_name/articles/:article_timestamp_id"         => "api/v1/articles#show"
    patch  "/api/v1/users/:user_name/articles/:article_timestamp_id"         => "api/v1/articles#update"
    get    "/articles.atom"                                                  => "atom_articles#index", as: :atom_articles, defaults: { format: :atom }
    get    "/articles"                                                       => "articles#index", as: :articles
    post   "/articles"                                                       => "articles#create"
    get    "/articles/new"                                                   => "articles#new", as: :new_article
    get    "/blog/users/:user_name/:article_timestamp_id"                    => redirect("/@%{user_name}/%{article_timestamp_id}", status: 301)
    post   "/export"                                                         => "exports#create", as: :export
    post   "/invitations"                                                    => "invitations#create", as: :invitations
    get    "/invitations/new"                                                => "invitations#new", as: :new_invitation
    delete "/issue_comments/:issue_comment_id"                               => "issue_comments#destroy", as: :issue_comment
    patch  "/issue_comments/:issue_comment_id"                               => "issue_comments#update"
    post   "/issue_comments/:issue_comment_id/reactions"                     => "issue_comment_reactions#create", as: :issue_comment_reactions
    delete "/issue_comments/:issue_comment_id/reactions/:reaction_name"      => "issue_comment_reactions#destroy", as: :issue_comment_reaction
    get    "/issues"                                                         => "issues#index", as: :issues
    post   "/issues"                                                         => "issues#create"
    get    "/issues/new"                                                     => "issues#new", as: :new_issue
    delete "/issues/:issue_incremental_id"                                   => "issues#destroy", as: :issue
    get    "/issues/:issue_incremental_id"                                   => "issues#show"
    patch  "/issues/:issue_incremental_id"                                   => "issues#update"
    post   "/issues/:issue_incremental_id/comments"                          => "issue_comments#create", as: :issue_comments
    post   "/issues/:issue_incremental_id/reactions"                         => "issue_reactions#create", as: :issue_reactions
    delete "/issues/:issue_incremental_id/reactions/:reaction_name"          => "issue_reactions#destroy", as: :issue_reaction
    delete "/issues/:issue_incremental_id/subscription"                      => "issue_subscriptions#destroy", as: :issue_subscription
    post   "/issues/:issue_incremental_id/subscription"                      => "issue_subscriptions#create"
    patch  "/issues/:issue_incremental_id"                                   => "issues#update"
    get    "/pages/*page_title"                                              => redirect("/wiki/%{page_title}", status: 301)
    get    "/settings"                                                       => "community_settings#show", as: :settings
    patch  "/settings"                                                       => "community_settings#update"
    get    "/settings/hooks"                                                 => "hooks#index", as: :hooks
    post   "/settings/hooks"                                                 => "hooks#create"
    get    "/settings/hooks/new"                                             => "hooks#new", as: :new_hook
    delete "/settings/hooks/:hook_id"                                        => "hooks#destroy", as: :hook
    get    "/settings/hooks/:hook_id"                                        => "hooks#edit"
    patch  "/settings/hooks/:hook_id"                                        => "hooks#update"
    get    "/settings/members"                                               => "community_members#index", as: :community_memberships
    delete "/settings/members/:community_membership_id"                      => "community_members#destroy", as: :community_membership
    patch  "/settings/members/:community_membership_id"                      => "community_members#update"
    get    "/settings/templates"                                             => "templates#index", as: :templates
    post   "/settings/templates"                                             => "templates#create"
    get    "/settings/templates/new"                                         => "templates#new", as: :new_template
    delete "/settings/templates/:template_id"                                => "templates#destroy", as: :template
    get    "/settings/templates/:template_id"                                => "templates#show"
    patch  "/settings/templates/:template_id"                                => "templates#update"
    delete "/star"                                                           => "community_stars#destroy", as: :community_star
    post   "/star"                                                           => "community_stars#create"
    get    "/stargazers"                                                     => "stargazers#index", as: :stargazers
    get    "/tags/:tag_name.atom"                                            => "atom_tags#show", as: :atom_tag, defaults: { format: :atom }
    get    "/tags/:tag_name"                                                 => "tags#show", as: :tag
    get    "/wiki.atom"                                                      => "atom_pages#index", as: :atom_pages, defaults: { format: :atom }
    get    "/wiki"                                                           => "pages#index", as: :pages
    post   "/wiki"                                                           => "pages#create"
    get    "/wiki/new"                                                       => "pages#new", as: :new_page
    get    "/wiki/*page_title/edit"                                          => "pages#edit", as: :edit_page
    get    "/wiki/*page_title/commits"                                       => "commits#index", as: :commits
    get    "/wiki/*page_title/commits/:hex_id"                               => "commits#show", as: :commit, constraints: { hex_id: /\h{40}/ }
    get    "/wiki/*page_title/presentation"                                  => "page_presentations#show", as: :page_presentation
    get    "/wiki/*page_title/raw"                                           => "raws#show", as: :raw
    post   "/wiki/*page_title/rollbacks/:hex_id"                             => "rollbacks#create", as: :rollbacks, constraints: { hex_id: /\h{40}/ }
    delete "/wiki/*page_title"                                               => "pages#destroy", as: :page, format: false
    get    "/wiki/*page_title"                                               => "pages#show", format: false
    patch  "/wiki/*page_title"                                               => "pages#update", format: false
    get    "/@:user_name.atom"                                               => "atom_user_articles#index", as: :atom_user_articles, defaults: { format: :atom }
    delete "/@:user_name/:article_timestamp_id"                              => "articles#destroy", as: :user_article
    get    "/@:user_name/:article_timestamp_id"                              => "articles#show"
    patch  "/@:user_name/:article_timestamp_id"                              => "articles#update"
    get    "/@:user_name/:article_timestamp_id/edit"                         => "articles#edit", as: :edit_user_article
    get    "/@:user_name/:article_timestamp_id/presentation"                 => "article_presentations#show", as: :article_presentation
    get    "/@:user_name/:article_timestamp_id/raw"                          => "raw_articles#show", as: :raw_article
    post   "/@:user_name/:article_timestamp_id/reactions"                    => "article_reactions#create", as: :article_reactions
    delete "/@:user_name/:article_timestamp_id/reactions/:reaction_name"     => "article_reactions#destroy", as: :article_reaction
  end
end