@@ -16,11 +16,13 @@ class Hacker
1616 #this is a flag to let us know if this Hacker can administrate the site or not.
1717 key :admin , Boolean , :default => false
1818
19- #the list of emails this user is following
20- key :following , Array , :typecast => 'ObjectId'
19+ #the list of hackers this hacker is following
20+ key :following_ids , Array
21+ many :following , :in => :following_ids , :class_name => 'Hacker'
2122
22- #the list of emails of users that are following this user
23- key :followers , Array , :typecast => 'ObjectId'
23+ #the list of hackers that are following this hacker
24+ key :followers_ids , Array
25+ many :followers , :in => :followers_ids , :class_name => 'Hacker'
2426
2527 #we don't want to store the password (or the confirmation), so we just make an accessor
2628 attr_accessor :password , :password_confirmation
@@ -70,6 +72,14 @@ def gravatar_url
7072 "http://www.gravatar.com/avatar/#{ MD5 ::md5 ( email . downcase ) } "
7173 end
7274
75+ #this function makes the hacker follow the followee
76+ def follow! followee
77+ following << followee
78+ save
79+ followee . followers << self
80+ followee . save
81+ end
82+
7383 private
7484
7585 #we're going to use the SHA1 encryption method for now.
0 commit comments