blob: f12f09193489bb58a0916bfd2a103d4630ecaf1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a key.
#
class Key < ::Gitlab::Config::Entry::Simplifiable
strategy :SimpleKey, if: -> (config) { config.is_a?(String) || config.is_a?(Symbol) }
strategy :ComplexKey, if: -> (config) { config.is_a?(Hash) }
class SimpleKey < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
validations do
validates :config, key: true
end
def self.default
'default'
end
def value
super.to_s
end
end
class ComplexKey < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
ALLOWED_KEYS = %i[files prefix].freeze
REQUIRED_KEYS = %i[files].freeze
validations do
validates :config, allowed_keys: ALLOWED_KEYS
validates :config, required_keys: REQUIRED_KEYS
end
entry :files, Entry::Files,
description: 'Files that should be used to build the key'
entry :prefix, Entry::Prefix,
description: 'Prefix that is added to the final cache key'
end
class UnknownStrategy < ::Gitlab::Config::Entry::Node
def errors
["#{location} should be a hash, a string or a symbol"]
end
end
def self.default
'default'
end
end
end
end
end
end
|