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

.anonymousObject

return an anonymous user



11
12
13
14
15
# File 'app/models/user.rb', line 11

def self.anonymous
  User.find_by_email('[email protected]')
rescue
  raise 'No anonymous user found'
end

Instance Method Details

#deliver_password_reset_instructions!Object

email notifications



36
37
38
39
# File 'app/models/user.rb', line 36

def deliver_password_reset_instructions!
  reset_perishable_token!
  Notifier.deliver_password_reset_instructions(self)
end

#has_role?(target_roles) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_role?(target_roles)
  target_roles = [target_roles] if target_roles.is_a? String
  roles.any? { |role| target_roles.include? role  }
end

#nameObject



17
18
19
# File 'app/models/user.rb', line 17

def name   
  "#{first_name} #{last_name}"
end

#rolesObject



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

def roles
  (read_attribute(:roles) || []).split(' ')
end

#roles=(input) ⇒ Object



21
22
23
24
# File 'app/models/user.rb', line 21

def roles=(input)
  write_attribute(:roles, input) if input.is_a? String
  write_attribute(:roles, input.join(' ')) if input.is_a? Array
end