forked from sigmike/peer4commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rb
More file actions
44 lines (36 loc) · 959 Bytes
/
user.rb
File metadata and controls
44 lines (36 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable
devise :database_authenticatable, :registerable, :recoverable,
:rememberable, :trackable, :validatable
devise :omniauthable, :omniauth_providers => [:github]
validates :bitcoin_address, :bitcoin_address => true
has_many :tips
def github_url
"https://github.com/#{nickname}"
end
def balance
tips.unpaid.sum(:amount)
end
after_create :generate_login_token!
def generate_login_token!
if login_token.blank?
self.update login_token: SecureRandom.urlsafe_base64
end
end
def full_name
if !name.blank?
name
elsif !nickname.blank?
nickname
else
email
end
end
def self.update_cache
find_each do |user|
user.update commits_count: user.tips.count
user.update withdrawn_amount: user.tips.paid.sum(:amount)
end
end
end