Class: Gitlab::Triage::Resource::Base
- Inherits:
-
Object
- Object
- Gitlab::Triage::Resource::Base
show all
- Defined in:
- lib/gitlab/triage/resource/base.rb
Constant Summary
collapse
- CONFIDENTIAL_TEXT =
'(confidential)'
- SOURCE_ERROR_MSG =
'This resource is missing project_id and group_id and unable to parse source.'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource, parent: nil, network: nil, redact_confidentials: true) ⇒ Base
Returns a new instance of Base.
24
25
26
27
28
29
30
|
# File 'lib/gitlab/triage/resource/base.rb', line 24
def initialize(
resource, parent: nil, network: nil, redact_confidentials: true)
@resource = resource
@parent = parent
@network = network
@redact_confidentials = redact_confidentials
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
9
10
11
|
# File 'lib/gitlab/triage/resource/base.rb', line 9
def parent
@parent
end
|
#resource ⇒ Object
Returns the value of attribute resource.
9
10
11
|
# File 'lib/gitlab/triage/resource/base.rb', line 9
def resource
@resource
end
|
Class Method Details
.define_field(name, &block) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/gitlab/triage/resource/base.rb', line 14
def self.define_field(name, &block)
define_method(name) do
if redact_confidential_attributes?
CONFIDENTIAL_TEXT
else
instance_eval(&block)
end
end
end
|
Instance Method Details
#build_url(params: {}, options: {}) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/gitlab/triage/resource/base.rb', line 76
def build_url(params: {}, options: {})
UrlBuilders::UrlBuilder.new(
url_opts
.merge(options)
.merge(params: { per_page: 100 }.merge(params))
).build
end
|
#expand_resource!(params: {}) ⇒ Object
45
46
47
48
|
# File 'lib/gitlab/triage/resource/base.rb', line 45
def expand_resource!(params: {})
resource.merge!(
network.query_api_cached(resource_url(params: params)).first)
end
|
#network ⇒ Object
39
40
41
|
# File 'lib/gitlab/triage/resource/base.rb', line 39
def network
parent&.network || @network
end
|
#redact_confidential_attributes? ⇒ Boolean
34
35
36
37
|
# File 'lib/gitlab/triage/resource/base.rb', line 34
def redact_confidential_attributes?
parent&.redact_confidential_attributes? ||
(@redact_confidentials && resource[:confidential])
end
|
#resource_id ⇒ Object
62
63
64
|
# File 'lib/gitlab/triage/resource/base.rb', line 62
def resource_id
resource[:iid]
end
|
#resource_url(params: {}, sub_resource_type: nil) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/gitlab/triage/resource/base.rb', line 66
def resource_url(params: {}, sub_resource_type: nil)
build_url(
params: params,
options: {
resource_id: resource_id,
sub_resource_type: sub_resource_type
}
)
end
|
#source ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/gitlab/triage/resource/base.rb', line 93
def source
if resource[:project_id]
'projects'
elsif resource[:group_id]
'groups'
else
raise ArgumentError, SOURCE_ERROR_MSG
end
end
|
#source_resource ⇒ Object
50
51
52
|
# File 'lib/gitlab/triage/resource/base.rb', line 50
def source_resource
@source_resource ||= network.query_api_cached(source_url).first
end
|
#source_url ⇒ Object
54
55
56
|
# File 'lib/gitlab/triage/resource/base.rb', line 54
def source_url
build_url(options: { resource_type: nil })
end
|
#url(params = {}) ⇒ Object
58
59
60
|
# File 'lib/gitlab/triage/resource/base.rb', line 58
def url(params = {})
build_url(params: params)
end
|
#url_opts ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/gitlab/triage/resource/base.rb', line 84
def url_opts
{
network_options: network.options,
resource_type: self.class.name.demodulize.underscore.pluralize,
source: source,
source_id: resource[:"#{source.singularize}_id"]
}
end
|