Class: Sem::API::Team
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Sem::API::Team
show all
- Extended by:
- Base
- Defined in:
- lib/sem/api/team.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Base
api_logger, client, create_new_api_client
Constructor Details
#initialize(org_name, team) ⇒ Team
Returns a new instance of Team.
34
35
36
37
38
|
# File 'lib/sem/api/team.rb', line 34
def initialize(org_name, team)
@org_name = org_name
super(team)
end
|
Instance Attribute Details
#org_name ⇒ Object
Returns the value of attribute org_name.
32
33
34
|
# File 'lib/sem/api/team.rb', line 32
def org_name
@org_name
end
|
Class Method Details
.all ⇒ Object
4
5
6
|
# File 'lib/sem/api/team.rb', line 4
def self.all
Sem::API::Org.all.pmap(&:teams).flatten
end
|
.create!(team_srn, args) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/sem/api/team.rb', line 22
def self.create!(team_srn, args)
org_name, team_name = Sem::SRN.parse_team(team_srn)
team = client.teams.create_for_org!(org_name, args.merge(:name => team_name))
new(org_name, team)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
end
|
.find!(team_srn) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/sem/api/team.rb', line 8
def self.find!(team_srn)
org_name, team_name = Sem::SRN.parse_team(team_srn)
team = client.teams.list_for_org!(org_name).find { |t| t.name == team_name }
if team.nil?
raise Sem::Errors::ResourceNotFound.new("Team", [org_name, team_name])
end
new(org_name, team)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Team", [org_name, team_name])
end
|
Instance Method Details
#add_project(project) ⇒ Object
62
63
64
65
66
|
# File 'lib/sem/api/team.rb', line 62
def add_project(project)
Sem::API::Base.client.projects.attach_to_team!(project.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Project", [project.full_name])
end
|
#add_shared_config(config) ⇒ Object
74
75
76
77
78
|
# File 'lib/sem/api/team.rb', line 74
def add_shared_config(config)
Sem::API::Base.client.shared_configs.attach_to_team!(config.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [config.full_name])
end
|
#add_user(username) ⇒ Object
50
51
52
53
54
|
# File 'lib/sem/api/team.rb', line 50
def add_user(username)
Sem::API::Base.client.users.attach_to_team!(username, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("User", [username])
end
|
#delete! ⇒ Object
86
87
88
|
# File 'lib/sem/api/team.rb', line 86
def delete!
Sem::API::Base.client.teams.delete!(id)
end
|
#full_name ⇒ Object
40
41
42
|
# File 'lib/sem/api/team.rb', line 40
def full_name
"#{org_name}/#{name}"
end
|
#projects ⇒ Object
94
95
96
|
# File 'lib/sem/api/team.rb', line 94
def projects
Sem::API::Base.client.projects.list_for_team!(id).map { |project| Sem::API::Project.new(org_name, project) }
end
|
#remove_project(project) ⇒ Object
68
69
70
71
72
|
# File 'lib/sem/api/team.rb', line 68
def remove_project(project)
Sem::API::Base.client.projects.detach_from_team!(project.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Project", [project.full_name])
end
|
#remove_shared_config(config) ⇒ Object
80
81
82
83
84
|
# File 'lib/sem/api/team.rb', line 80
def remove_shared_config(config)
Sem::API::Base.client.shared_configs.detach_from_team!(config.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [config.full_name])
end
|
#remove_user(username) ⇒ Object
56
57
58
59
60
|
# File 'lib/sem/api/team.rb', line 56
def remove_user(username)
Sem::API::Base.client.users.detach_from_team!(username, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("User", [username])
end
|
#shared_configs ⇒ Object
98
99
100
|
# File 'lib/sem/api/team.rb', line 98
def shared_configs
Sem::API::Base.client.shared_configs.list_for_team!(id).map { |config| Sem::API::SharedConfig.new(org_name, config) }
end
|
#update!(args) ⇒ Object
44
45
46
47
48
|
# File 'lib/sem/api/team.rb', line 44
def update!(args)
new_team = Sem::API::Base.client.teams.update!(id, args)
self.class.new(@org_name, new_team)
end
|
#users ⇒ Object
90
91
92
|
# File 'lib/sem/api/team.rb', line 90
def users
Sem::API::Base.client.users.list_for_team!(id).map { |user| Sem::API::User.new(user) }
end
|