Class: GitContacts::User

Inherits:
Object
  • Object
show all
Defined in:
lib/gitcontacts/User.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ User

Returns a new instance of User.



20
21
22
23
# File 'lib/gitcontacts/User.rb', line 20

def initialize email
  @email = email
  @obj = UserObject::access email
end

Class Method Details

.allObject



16
17
18
# File 'lib/gitcontacts/User.rb', line 16

def self::all
  UserObject::all
end

.create(hash) ⇒ Object



9
10
11
12
13
14
# File 'lib/gitcontacts/User.rb', line 9

def self::create hash
  # some keys are optional
  obj = UserObject.new
  obj.set_email hash[:email]
  obj.password = Digest::MD5.hexdigest(hash[:password])
end

.exist?(email) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/gitcontacts/User.rb', line 5

def self::exist? email
  UserObject::exist?(email)
end

Instance Method Details

#add_contacts(gid) ⇒ Object



67
68
69
# File 'lib/gitcontacts/User.rb', line 67

def add_contacts gid
  @obj.contacts << gid if @obj
end

#add_request(request_id) ⇒ Object



75
76
77
# File 'lib/gitcontacts/User.rb', line 75

def add_request request_id
  @obj.requests << request_id if @obj
end

#getcontactsObject



42
43
44
# File 'lib/gitcontacts/User.rb', line 42

def getcontacts
  @obj.contacts.members if @obj
end

#getemailObject

def getname

@obj.name.value if @obj

end



33
34
35
36
# File 'lib/gitcontacts/User.rb', line 33

def getemail
  #@obj.email if @obj
  @email
end

#getinfoObject



50
51
52
53
54
55
56
57
# File 'lib/gitcontacts/User.rb', line 50

def getinfo
  {
    :uid => getuid,
    :email => getemail,
    :contacts => getcontacts,
    :request => getrequests
  }
end

#getpasswordObject



38
39
40
# File 'lib/gitcontacts/User.rb', line 38

def getpassword
  @obj.password.value if @obj
end

#getrequestsObject



46
47
48
# File 'lib/gitcontacts/User.rb', line 46

def getrequests
  @obj.requests.members if @obj
end

#getuidObject



25
26
27
# File 'lib/gitcontacts/User.rb', line 25

def getuid
  getemail
end

#password_correct?(sha) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/gitcontacts/User.rb', line 59

def password_correct? sha
  sha == getpassword && sha != nil && sha != ""
end

#remove_contacts(gid) ⇒ Object



71
72
73
# File 'lib/gitcontacts/User.rb', line 71

def remove_contacts gid
  @obj.contacts.delete gid if @obj
end

#remove_request(request_id) ⇒ Object



79
80
81
# File 'lib/gitcontacts/User.rb', line 79

def remove_request request_id
  @obj.requests.delete request_id if @obj
end

#set_password(sha) ⇒ Object



63
64
65
# File 'lib/gitcontacts/User.rb', line 63

def set_password sha
  @obj.password = sha if sha != nil && sha != ""
end