Skip to content

Instantly share code, notes, and snippets.

@serinuntius
Last active August 28, 2018 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serinuntius/64f956f5153ae9890284a084576c7728 to your computer and use it in GitHub Desktop.
Save serinuntius/64f956f5153ae9890284a084576c7728 to your computer and use it in GitHub Desktop.
Rubyのコードのリーディングをして、どうすればoptionのscopeを変更できるか調べてみる。

調査の仕方のメモ

変更したい対象となるクラスをまず読む

ここでoptionというメソッドが呼ばれている。 https://github.com/kazasiki/omniauth-line/blob/master/lib/omniauth/strategies/line.rb#L8

どこで定義されているメソッドかわからないので、継承してるクラス(OmniAuth::Strategies::OAuth2)を調べてみる。

OmniAuth::Strategies::OAuth2を読む

https://github.com/omniauth/omniauth-oauth2/blob/master/lib/omniauth/strategies/oauth2.rb#L23-L31

ここでも既にoptionは利用されている。 ということは更に別のクラスで定義されているメソッドのはず。

よく読んでみると、include OmniAuth::Strategy と書いてある。(https://github.com/omniauth/omniauth-oauth2/blob/master/lib/omniauth/strategies/oauth2.rb#L15 )

OmniAuth::Strategy を読んでみよう。

OmniAuth::Strategyを読む

def option で検索かけてみる。 あった! https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L75-L77

これは、単純に namevalue を指定すれば値を設定できるメソッドのようだ。 外から OmniAuth::Strategies::Lineoption というメソッドが呼び出せたら、 option :scope, 'email' が 設定できそう!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment