Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/models/user.rb
Constant Summary collapse
- BLANK_FIELD =
''
- DEFAULT_NICK =
'Default user'
Class Method Summary collapse
Instance Method Summary collapse
- #activate ⇒ Object
- #deactivate ⇒ Object
- #full_name ⇒ Object
- #full_name_and_nickname ⇒ Object
- #location ⇒ Object
Class Method Details
.default ⇒ Object
10 11 12 |
# File 'lib/models/user.rb', line 10 def self.default find_or_create_by_active(true) end |
.find_or_create_active ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/models/user.rb', line 14 def self.find_or_create_active last_user = User.last if last_user.present? last_user.active = true last_user.save last_user else self.default end end |
Instance Method Details
#activate ⇒ Object
25 26 27 28 29 |
# File 'lib/models/user.rb', line 25 def activate self.active = true self.save self end |
#deactivate ⇒ Object
31 32 33 34 35 |
# File 'lib/models/user.rb', line 31 def deactivate self.active = false self.save self end |
#full_name ⇒ Object
37 38 39 |
# File 'lib/models/user.rb', line 37 def full_name "#{first_name.present? ? first_name : ''} #{last_name.present? ? last_name : ''}".strip end |
#full_name_and_nickname ⇒ Object
41 42 43 |
# File 'lib/models/user.rb', line 41 def full_name_and_nickname "#{full_name.present? ? full_name : ''} #{full_name.present? ? "(#{nickname})" : nickname }".strip end |
#location ⇒ Object
45 46 47 |
# File 'lib/models/user.rb', line 45 def location "#{self.city}#{self.city.present? && self.country.present? ? ', ' : ''}#{self.country}".strip end |