Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_with_omniauth(auth) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'app/models/user.rb', line 16

def self.create_with_omniauth(auth)
  create! do |user|
    user.provider = auth["provider"]
    user.uid = auth["uid"]
    user.display_name = auth["info"]["name"]
    user.user_name = auth["info"]["nickname"]
    user.email = auth["info"]["email"]
  end
end

.find_or_create_with_omniauth(auth) ⇒ Object


26
27
28
# File 'app/models/user.rb', line 26

def self.find_or_create_with_omniauth(auth)
  find_with_omniauth(auth) || create_with_omniauth(auth)
end

.find_with_omniauth(auth) ⇒ Object


30
31
32
# File 'app/models/user.rb', line 30

def self.find_with_omniauth(auth)
  find_by_provider_and_uid(auth["provider"], auth["uid"])
end

Instance Method Details

#projectsObject


5
6
7
8
9
10
11
12
13
14
# File 'app/models/user.rb', line 5

def projects
  all_user_names = (organizations || []) + [user_name]
  uids = all_user_names.map do |username|
    uid = InchCI::ProjectUID.new({
        :service => provider, :user => username, :repo => '%'
      }).project_uid
  end
  like_condition = (['uid LIKE ?'] * uids.size).join(' OR ')
  Project.includes(:default_branch).where(like_condition, *uids)
end