Class: User

Inherits:
ApplicationRecord show all
Defined in:
app/models/user.rb

Overview

User Stores information about the user. It is created automatically when authenticated Copied from Github data

User(id: integer,

name: string,
admin: boolean,
staff: boolean,
karma: integer,
github_avatar_url: string,
github_html_url: string,
github_id: string,
github_login: string,
github_company: string,
github_type: string,
github_blog: string,
github_location: string,
github_bio: string,
github_created_at: datetime,
github_updated_at: datetime,
email: string,
remember_created_at: datetime,
sign_in_count: integer, current_sign_in_at: datetime,
last_sign_in_at: datetime,
current_sign_in_ip: inet,
last_sign_in_ip: inet,
created_at: datetime,
updated_at: datetime)

Class Method Summary collapse

Class Method Details

.return_user(github_user) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/user.rb', line 59

def self.return_user(github_user)
  return nil if github_user&.id.nil?
  u = User.where(id: github_user.id).first_or_create do |user|
    user.name              = github_user.name # assuming the user model has a name
    user.github_avatar_url = github_user.avatar_url || ''
    user.github_html_url   = github_user.html_url || ''
    user.github_id         = github_user.id
    user.      = github_user.
    user.github_company    = github_user.company || ''
    user.github_type       = github_user.type
    user.github_blog       = github_user.blog || ''
    user.github_location   = github_user.location || ''
    user.email             = github_user.email
    user.github_bio        = github_user.bio || ''
    user.github_created_at = github_user.created_at
    user.github_updated_at = github_user.updated_at
  end
  if u.errors.any?
    logger.debug(pp u.errors)
    return u.errors
  end
  u
  # TODO: It is possible that first_or_create with a block does not update the user
  # Verify and change to first_or_initialize + update
end