Class: Gitlab::Ci::Variables::Collection::Sort
- Inherits:
-
Object
- Object
- Gitlab::Ci::Variables::Collection::Sort
- Includes:
- Utils::StrongMemoize, TSort
- Defined in:
- lib/gitlab/ci/variables/collection/sort.rb
Instance Method Summary collapse
-
#errors ⇒ Object
errors sorts an array of variables, ignoring unknown variable references, and returning an error string if a circular variable reference is found.
-
#initialize(collection) ⇒ Sort
constructor
A new instance of Sort.
- #valid? ⇒ Boolean
Constructor Details
#initialize(collection) ⇒ Sort
Returns a new instance of Sort.
11 12 13 14 15 16 |
# File 'lib/gitlab/ci/variables/collection/sort.rb', line 11 def initialize(collection) raise(ArgumentError, "A Gitlab::Ci::Variables::Collection object was expected") unless collection.is_a?(Collection) @collection = collection end |
Instance Method Details
#errors ⇒ Object
errors sorts an array of variables, ignoring unknown variable references, and returning an error string if a circular variable reference is found
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/ci/variables/collection/sort.rb', line 24 def errors strong_memoize(:errors) do # Check for cyclic dependencies and build error message in that case cyclic_vars = each_strongly_connected_component.filter_map do |component| component.map { |v| v[:key] }.inspect if component.size > 1 end "circular variable reference detected: #{cyclic_vars.join(', ')}" if cyclic_vars.any? end end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/gitlab/ci/variables/collection/sort.rb', line 18 def valid? errors.nil? end |