I have this code that creates (or updates) a user from an omniauth hash parameter:
def self.find_or_create_from_auth_hash(auth_hash)
uid = auth_hash['uid']
provider = auth_hash['provider']
user = find_or_create_by(uid: uid, provider: provider)
user.name = auth_hash['info']['name'] || ''
user.email = auth_hash['info']['email']
user.nickname = auth_hash['info']['nickname']
user.avatar = auth_hash['info']['image'] || ''
user.access_token = auth_hash['credentials']['token']
user.location = auth_hash['extra']['raw_info']['location'] || ''
user.company = auth_hash['extra']['raw_info']['company'] || ''
user.member_since = auth_hash['extra']['raw_info']['created_at'] || ''
user if user.save
end
It is working, but it looks unpleasant. What can be changed in this piece of code, making it easier to read and/or beautiful?
omniauthhash \$\endgroup\$