Class: User
Defined Under Namespace
Modules: Extensions, Liking, Listable, Omniauthable
Constant Summary
collapse
- PARENT_TYPES =
['area', 'project']
Class Method Summary
collapse
Instance Method Summary
collapse
included
Class Method Details
.languages(query = nil) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/models/user.rb', line 52
def self.languages(query = nil)
options = []
AVAILABLE_LANGUAGES.merge(OTHER_LANGUAGES).each do |locale, language|
next if query && !language.downcase.match(query.downcase)
if query
options << { id: locale, name: language }
else
options << [language, locale]
end
end
options
end
|
Instance Method Details
#area_tokens ⇒ Object
96
97
98
|
# File 'app/models/user.rb', line 96
def area_tokens
areas
end
|
#area_tokens=(tokens) ⇒ Object
92
93
94
|
# File 'app/models/user.rb', line 92
def area_tokens=(tokens)
self.area_ids = Area.ids_from_tokens(tokens)
end
|
#best_available_name ⇒ Object
104
105
106
|
# File 'app/models/user.rb', line 104
def best_available_name
lastfm_user_name || full_name
end
|
#email_required? ⇒ Boolean
40
41
42
|
# File 'app/models/concerns/user/omniauthable.rb', line 40
def email_required?
super && provider.blank?
end
|
#foreign_language_tokens ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/user.rb', line 80
def foreign_language_tokens
options = []
User.languages.each do |language|
next unless (foreign_languages || []).include?(language.second)
options << { id: language.second, name: language.first }
end
options
end
|
#foreign_language_tokens=(tokens) ⇒ Object
76
77
78
|
# File 'app/models/user.rb', line 76
def foreign_language_tokens=(tokens)
self.foreign_languages = tokens.split(',')
end
|
#full_name ⇒ Object
100
101
102
|
# File 'app/models/user.rb', line 100
def full_name
[first_name, last_name].join(' ')
end
|
#is_master? ⇒ Boolean
68
69
70
|
# File 'app/models/user.rb', line 68
def is_master?
roles.where(name: 'Master').any?
end
|
#languages ⇒ Object
72
73
74
|
# File 'app/models/user.rb', line 72
def languages
(foreign_languages || []) + [language]
end
|
#password_required? ⇒ Boolean
36
37
38
|
# File 'app/models/concerns/user/omniauthable.rb', line 36
def password_required?
super && provider.blank?
end
|
#update_with_password(params, *options) ⇒ Object
44
45
46
47
48
49
50
|
# File 'app/models/concerns/user/omniauthable.rb', line 44
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
|