Class: CodeManager::Invitation
Overview
Manager for invitation codes
Instance Attribute Summary
Attributes inherited from CodeManager
#code, #user
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CodeManager
handler, #initialize
Constructor Details
This class inherits a constructor from CodeManager
Class Method Details
.code_for_user(user) ⇒ Object
11
12
13
14
15
16
|
# File 'app/services/code_manager/invitation.rb', line 11
def self.code_for_user(user)
code = code_type.codes.active.find_by(user: user)
code = code_type.codes.create(user: user) if code.nil?
code
end
|
6
7
8
|
# File 'app/services/code_manager/invitation.rb', line 6
def self.code_type
@code_type ||= CodeType.find_by!(slug: 'invitation')
end
|
Instance Method Details
#activate(invitee) ⇒ Object
25
26
27
28
29
30
|
# File 'app/services/code_manager/invitation.rb', line 25
def activate(invitee)
return if invitee.nil? || @code.quantity < 1
@code.decrement!(:quantity)
invitee.update(inviter_id: @code.user_id)
end
|
#code_is_valid? ⇒ Boolean
18
19
20
21
22
|
# File 'app/services/code_manager/invitation.rb', line 18
def code_is_valid?
return false if @code.nil?
@code.active? && @code.code_type == self.class.code_type
end
|