- 追加された行はこの色です。
- 削除された行はこの色です。
[[Mastodonを読む]]
#contents
*はじめに [#ae0ea627]
さて、確認環境ができたのでMastodon本体の読解に入ります。まずは、「http://mastodon.dev/」と「/」にアクセスしたときに何が行われるかについて見ていきましょう。
*config/routes.rb [#a6f1eeeb]
というわけで、routes.rbを見て「/」にアクセスされたときにどのコントローラのどのメソッドが呼び出されるのかを確認します。ついでにroutes.rbに定義されているそれ以外のルーティングについても見ていきます。
**認証周り [#gcf2cdf0]
まず目に入るのは以下の記述です。
#code(Ruby){{
devise_for :users, path: 'auth', controllers: {
sessions: 'auth/sessions',
registrations: 'auth/registrations',
passwords: 'auth/passwords',
confirmations: 'auth/confirmations',
}
}}
認証処理には[[devise>https://github.com/plataformatec/devise]]を使っていることがわかります。今回は、登録、ログインはできているものとしてdeviseの中身には踏み込まないことにします。
**ユーザ周り [#f65db7c3]
次に目に入るのは以下の部分。
#code(Ruby){{
get '/users/:username', to: redirect('/@%{username}'), constraints: { format: :html }
resources :accounts, path: 'users', only: [:show], param: :username do
resources :stream_entries, path: 'updates', only: [:show] do
member do
get :embed
end
end
get :remote_follow, to: 'remote_follow#new'
post :remote_follow, to: 'remote_follow#create'
resources :followers, only: [:index], controller: :follower_accounts
resources :following, only: [:index], controller: :following_accounts
resource :follow, only: [:create], controller: :account_follow
resource :unfollow, only: [:create], controller: :account_unfollow
end
get '/@:username', to: 'accounts#show', as: :short_account
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
}}
あるユーザについて、ユーザのホームを表示する、フォロワーを表示する、トゥートを表示するなどが定義されています。
フォロー関係、onlyで1メソッドしか指定しないのなら一つのコントローラにまとめてしまっていいような気がするのですが、将来拡張を考えてのことでしょうか。
って、確認のためにポチポチしてると画面全体再描画されてないのにURL切り替わりますね。そんなことできるんだっけ?turbolinksだとできたかな。
**API周り [#o5c9c6d8]
ユーザ設定、サイト設定などのルーティングが続きますが飛ばします。
その後、APIと思われる記述があります。一部省略して載せると、
#code(Ruby){{
namespace :api do
省略
# JSON / REST API
namespace :v1 do
省略
get '/timelines/home', to: 'timelines#home', as: :home_timeline
get '/timelines/public', to: 'timelines#public', as: :public_timeline
get '/timelines/tag/:id', to: 'timelines#tag', as: :hashtag_timeline
省略
end
end
}}
config.rb中でtimelineという単語が出ているのはここだけです。怪しい。
**ルートとその他 [#tbed5ec8]
残りのルーティングは以下になります。
#code(Ruby){{
get '/web/(*any)', to: 'home#index', as: :web
get '/about', to: 'about#show'
get '/about/more', to: 'about#more'
get '/terms', to: 'about#terms'
root 'home#index'
}}
というわけで、home_controllerのindexメソッドが呼ばれる、ということのようです。
*おわりに [#d0aae6f5]
「/」がアクセスされたときにどのコントローラが呼ばれるかということでroutes.rbを見てきました。「/」が指定されたとき以外にもAPIに書かれているtimelineの記述など気になるものがありました。これらは今後読んでいくと明らかになっていくでしょう。