Class: InvitationCode

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/invitation_code.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_inviter_or(user) ⇒ Object


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

def self.default_inviter_or(user)
  if AppConfig.admins..present?
    inviter = User.find_by_username(AppConfig.admins..get)
  end
  inviter ||= user
  inviter
end

Instance Method Details

#add_invites!Object


18
19
20
# File 'app/models/invitation_code.rb', line 18

def add_invites!
  self.update_attributes(:count => self.count+100)
end

#can_be_used?Boolean


14
15
16
# File 'app/models/invitation_code.rb', line 14

def can_be_used?
  self.count > 0
end

#generate_tokenObject


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

def generate_token
  begin
    self.token = SecureRandom.hex(6)
  end while InvitationCode.exists?(:token => self[:token])
end

#set_default_invite_countObject


40
41
42
# File 'app/models/invitation_code.rb', line 40

def set_default_invite_count
  self.count = AppConfig['settings.invitations.count'] || 25
end

#to_paramObject


10
11
12
# File 'app/models/invitation_code.rb', line 10

def to_param
  token 
end

#use!Object


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

def use!
  self.update_attributes(:count => self.count-1)
end