0

ユーザーが見つからない場合は User または nil を返す関数があります。次のようになります。

  # Given an access token in the HTTP headers, it returns the User who owns the token
  #
  # @return [User] the user who owns the access token
  def set_api_user
    token = /(.*)=\"(.*)\"/.match(request.headers["Authorization"])[2]
    @api_user = ApiKey.find_by(access_token: token).user
  end

私の質問は、それが見つからない場合に User または nil を返すことをどのように文書化するのですか?

4

1 に答える 1

1

Yard では、エラー状態などのコードの動作を無視して、コメントに代替案を追加するだけです。

# @return [User,nil] the user who owns the access token

Yard レンダラーは、次のようなことを行います。


  • (ユーザー? ) set_api_user

    アクセストークンを所有するユーザー


小さな疑問符は、「おそらくこれを取得するか、またはゼロを取得する」という Yard の規則です。

于 2014-06-04T21:33:02.720 に答える