Class: Sem::API::Project
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Sem::API::Project
show all
- Extended by:
- Base
- Defined in:
- lib/sem/api/project.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, project) ⇒ Project
Returns a new instance of Project.
35
36
37
38
39
|
# File 'lib/sem/api/project.rb', line 35
def initialize(org_name, project)
@org_name = org_name
super(project)
end
|
Instance Attribute Details
#org_name ⇒ Object
Returns the value of attribute org_name.
33
34
35
|
# File 'lib/sem/api/project.rb', line 33
def org_name
@org_name
end
|
Class Method Details
.all ⇒ Object
4
5
6
|
# File 'lib/sem/api/project.rb', line 4
def self.all
Sem::API::Org.all.map(&:projects).flatten
end
|
.create!(project_srn, args) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/sem/api/project.rb', line 23
def self.create!(project_srn, args)
org_name, name = Sem::SRN.parse_project(project_srn)
project = client.projects.create_for_org!(org_name, args.merge(:name => name))
new(org_name, project)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
end
|
.find!(project_srn) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/sem/api/project.rb', line 8
def self.find!(project_srn)
org_name, project_name = Sem::SRN.parse_project(project_srn)
projects = client.projects.list_for_org!(org_name, :name => project_name)
project = projects.to_a.first
if project.nil?
raise Sem::Errors::ResourceNotFound.new("Project", [org_name, project_name])
end
new(org_name, project)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Project", [org_name, project_name])
end
|
Instance Method Details
#add_config_file(config_file) ⇒ Object
73
74
75
|
# File 'lib/sem/api/project.rb', line 73
def add_config_file(config_file)
Sem::API::Base.client.config_files.attach_to_project!(config_file.id, id)
end
|
#add_env_var(env_var) ⇒ Object
69
70
71
|
# File 'lib/sem/api/project.rb', line 69
def add_env_var(env_var)
Sem::API::Base.client.env_vars.attach_to_project!(env_var.id, id)
end
|
#add_secret(secret) ⇒ Object
49
50
51
52
53
|
# File 'lib/sem/api/project.rb', line 49
def add_secret(secret)
Sem::API::Base.client.secrets.attach_to_project!(secret.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Secret", [secret.full_name])
end
|
#config_files ⇒ Object
61
62
63
|
# File 'lib/sem/api/project.rb', line 61
def config_files
Sem::API::Base.client.config_files.list_for_project!(id).map { |file| Sem::API::File.new(file) }
end
|
#env_vars ⇒ Object
65
66
67
|
# File 'lib/sem/api/project.rb', line 65
def env_vars
Sem::API::Base.client.env_vars.list_for_project!(id).map { |var| Sem::API::EnvVar.new(var) }
end
|
#full_name ⇒ Object
41
42
43
|
# File 'lib/sem/api/project.rb', line 41
def full_name
"#{@org_name}/#{name}"
end
|
#remove_secret(secret) ⇒ Object
55
56
57
58
59
|
# File 'lib/sem/api/project.rb', line 55
def remove_secret(secret)
Sem::API::Base.client.secrets.detach_from_project!(secret.id, id)
rescue SemaphoreClient::Exceptions::NotFound
raise Sem::Errors::ResourceNotFound.new("Secret", [secret.full_name])
end
|
#secrets ⇒ Object
45
46
47
|
# File 'lib/sem/api/project.rb', line 45
def secrets
Sem::API::Base.client.secrets.list_for_project!(id).map { |secret| Sem::API::Secret.new(org_name, secret) }
end
|