Class: SimpleTeams::LeaveTeamService

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/service_objects/simple_teams/leave_team_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, team_id) ⇒ LeaveTeamService

Returns a new instance of LeaveTeamService.



7
8
9
10
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 7

def initialize(user_id, team_id)
  @user_id = user_id
  @team_id = team_id
end

Instance Attribute Details

#team_idObject

Returns the value of attribute team_id.



5
6
7
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 5

def team_id
  @team_id
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#membershipObject



31
32
33
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 31

def membership
  @membership ||= user.membership_for_team(team)
end

#performObject



18
19
20
21
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 18

def perform
  membership.destroy
  generate_notification
end

#teamObject



27
28
29
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 27

def team
  @team ||= SimpleTeams::Team.find(team_id)
end

#userObject



23
24
25
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 23

def user
  @user ||= SimpleTeams.member_class.find(user_id)
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/service_objects/simple_teams/leave_team_service.rb', line 12

def valid?
  self.errors.clear
  validate_not_last_owner
  !self.errors.any?
end