class Sem::API::Team

Attributes

org_name[R]

Public Class Methods

all() click to toggle source
# File lib/sem/api/team.rb, line 4
def self.all
  Sem::API::Org.all.pmap(&:teams).flatten
end
create!(team_srn, args) click to toggle source
# 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) click to toggle source
# 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
new(org_name, team) click to toggle source
Calls superclass method
# File lib/sem/api/team.rb, line 34
def initialize(org_name, team)
  @org_name = org_name

  super(team)
end

Public Instance Methods

add_project(project) click to toggle source
# 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_secret(secret) click to toggle source
# File lib/sem/api/team.rb, line 74
def add_secret(secret)
  Sem::API::Base.client.secrets.attach_to_team!(secret.id, id)
rescue SemaphoreClient::Exceptions::NotFound
  raise Sem::Errors::ResourceNotFound.new("Secret", [secret.full_name])
end
add_user(username) click to toggle source
# 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!() click to toggle source
# File lib/sem/api/team.rb, line 86
def delete!
  Sem::API::Base.client.teams.delete!(id)
end
full_name() click to toggle source
# File lib/sem/api/team.rb, line 40
def full_name
  "#{org_name}/#{name}"
end
projects() click to toggle source
# 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) click to toggle source
# 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_secret(secret) click to toggle source
# File lib/sem/api/team.rb, line 80
def remove_secret(secret)
  Sem::API::Base.client.secrets.detach_from_team!(secret.id, id)
rescue SemaphoreClient::Exceptions::NotFound
  raise Sem::Errors::ResourceNotFound.new("Secret", [secret.full_name])
end
remove_user(username) click to toggle source
# 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
secrets() click to toggle source
# File lib/sem/api/team.rb, line 98
def secrets
  Sem::API::Base.client.secrets.list_for_team!(id).map { |secret| Sem::API::Secret.new(org_name, secret) }
end
update!(args) click to toggle source
# 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() click to toggle source
# 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