Class: SimpleTeams::AcceptInvitationService
- Inherits:
-
Object
- Object
- SimpleTeams::AcceptInvitationService
- Includes:
- ActiveModel::Model
- Defined in:
- app/service_objects/simple_teams/accept_invitation_service.rb
Instance Attribute Summary collapse
-
#invitation_token ⇒ Object
Returns the value of attribute invitation_token.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(user_id, invitation_token) ⇒ AcceptInvitationService
constructor
A new instance of AcceptInvitationService.
- #invitation ⇒ Object
- #perform ⇒ Object
- #user ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(user_id, invitation_token) ⇒ AcceptInvitationService
Returns a new instance of AcceptInvitationService.
7 8 9 10 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 7 def initialize(user_id, invitation_token) @user_id = user_id @invitation_token = invitation_token end |
Instance Attribute Details
#invitation_token ⇒ Object
Returns the value of attribute invitation_token.
5 6 7 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 5 def invitation_token @invitation_token end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 5 def user_id @user_id end |
Instance Method Details
#invitation ⇒ Object
34 35 36 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 34 def invitation @invitation ||= Invitation.find_by(token: @invitation_token) end |
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 19 def perform ActiveRecord::Base.transaction do membership = team.memberships.create!( :member => user, :role => invitation.role ) invitation.update!(membership: membership) invitation.accepted! end end |
#user ⇒ Object
30 31 32 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 30 def user @user ||= SimpleTeams.member_class.find(user_id) end |
#valid? ⇒ Boolean
12 13 14 15 16 17 |
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 12 def valid? self.errors.clear validate_invitation_token validate_user_not_a_member !self.errors.any? end |