Class: SimpleTeams::InitializeTeamService

Inherits:
Object
  • Object
show all
Defined in:
app/service_objects/simple_teams/initialize_team_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, team) ⇒ InitializeTeamService

Returns a new instance of InitializeTeamService.



6
7
8
9
# File 'app/service_objects/simple_teams/initialize_team_service.rb', line 6

def initialize(user, team)
  @user = user
  @team = team
end

Instance Attribute Details

#teamObject

Returns the value of attribute team.



4
5
6
# File 'app/service_objects/simple_teams/initialize_team_service.rb', line 4

def team
  @team
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'app/service_objects/simple_teams/initialize_team_service.rb', line 4

def user
  @user
end

Instance Method Details

#performObject



15
16
17
18
19
20
21
22
# File 'app/service_objects/simple_teams/initialize_team_service.rb', line 15

def perform
  ActiveRecord::Base.transaction do
    team.memberships.create(
      :member => user,
      :role => :owner
    )
  end
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/service_objects/simple_teams/initialize_team_service.rb', line 11

def valid?
  !user.teams.include? team
end