Class: User

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

Constant Summary collapse

BLANK_FIELD =
''
DEFAULT_NICK =
'Default user'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



10
11
12
# File 'lib/models/user.rb', line 10

def self.default
  find_or_create_by_active(true)
end

.find_or_create_activeObject



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

#activateObject



25
26
27
28
29
# File 'lib/models/user.rb', line 25

def activate
  self.active = true
  self.save
  self
end

#deactivateObject



31
32
33
34
35
# File 'lib/models/user.rb', line 31

def deactivate
  self.active = false
  self.save
  self
end

#full_nameObject



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_nicknameObject



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

#locationObject



45
46
47
# File 'lib/models/user.rb', line 45

def location
  "#{self.city}#{self.city.present? && self.country.present? ? ', ' : ''}#{self.country}".strip
end