Class: Gitlab::Ci::Config::External::File::Base
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::External::File::Base
show all
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/config/external/file/base.rb
Constant Summary
collapse
- YAML_WHITELIST_EXTENSION =
/.+\.(yml|yaml)$/i.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#clear_memoization, #strong_memoize, #strong_memoized?
Constructor Details
#initialize(params, context) ⇒ Base
Returns a new instance of Base.
15
16
17
18
19
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 15
def initialize(params, context)
@params = params
@context = context
@errors = []
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def context
@context
end
|
#errors ⇒ Object
Returns the value of attribute errors.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def errors
@errors
end
|
#location ⇒ Object
Returns the value of attribute location.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def location
@location
end
|
#params ⇒ Object
Returns the value of attribute params.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def params
@params
end
|
Instance Method Details
#content ⇒ Object
41
42
43
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 41
def content
raise NotImplementedError, 'subclass must implement fetching raw content'
end
|
#eql?(other) ⇒ Boolean
65
66
67
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 65
def eql?(other)
other.hash == hash
end
|
#error_message ⇒ Object
37
38
39
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 37
def error_message
errors.first
end
|
#hash ⇒ Object
69
70
71
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 69
def hash
[params, context.project&.full_path, context.sha].hash
end
|
#invalid_extension? ⇒ Boolean
29
30
31
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 29
def invalid_extension?
location.nil? || !::File.basename(location).match?(YAML_WHITELIST_EXTENSION)
end
|
#invalid_location_type? ⇒ Boolean
25
26
27
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 25
def invalid_location_type?
!location.is_a?(String)
end
|
#matching? ⇒ Boolean
21
22
23
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 21
def matching?
location.present?
end
|
58
59
60
61
62
63
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 58
def metadata
{
context_project: context.project&.full_path,
context_sha: context.sha
}
end
|
#to_hash ⇒ Object
45
46
47
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 45
def to_hash
expanded_content_hash
end
|
#valid? ⇒ Boolean
33
34
35
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 33
def valid?
errors.none?
end
|
#validate! ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 49
def validate!
context.logger.instrument(:config_file_validation) do
validate_execution_time!
validate_location!
validate_content! if errors.none?
validate_hash! if errors.none?
end
end
|