下面显示的代码通常在将 rubygems、Omniauth 和 Omniauth-Facebook 集成到 rails 应用程序时使用。我需要逐行解释这段代码。
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end