Class: User

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

Direct Known Subclasses

FullyValidatedUser

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ User

Returns a new instance of User.



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

def initialize(*args)
  super(*args)
end

Class Method Details

.nobodyObject



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

def self.nobody
  User.new(:role=>Role.nobody)
end

.rootObject



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

def self.root
  User.where(:role_id=>Role.root.id)[0]
end

Instance Method Details

#confirm!Object



55
56
57
58
# File 'app/models/user.rb', line 55

def confirm!
  self.confirmed_at = DateTime::now
  save
end

#create_profileObject



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

def create_profile
  unless self.profile
    build_profile(:alias=>email)
    profile.save
  end
end

#role=(role) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/user.rb', line 42

def role=(role)
  if role.kind_of? Role
    self.role_id = role.id
  else
    role = role.to_s.camelize
    if role.is_numeric?
      self.role_id= role
    else
      self.role_id= Role.find_by_name(role).id
    end
  end
end

#role?(role) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
# File 'app/models/user.rb', line 32

def role?(role)
  if role.kind_of?(Role)
    return role==self.role
  elsif role.is_numeric?
    return self.role_id==role
  else
    return self.role.name.underscore==role.underscore
  end
end