secret_variables_for: rails readability versino

This commit is contained in:
Shinya Maeda 2017-07-06 00:13:01 +09:00
parent 5cb45b6a44
commit 5c68fa66cc

View file

@ -250,17 +250,11 @@ class Group < Namespace
end end
def secret_variables_for(ref, project) def secret_variables_for(ref, project)
list_of_ids = ([self] + ancestors).map { |l| l.id } list_of_ids = [self] + ancestors
variables = Ci::GroupVariable.where(group: list_of_ids)
order = list_of_ids.map.with_index do |id, index| variables = variables.unprotected unless project.protected_for?(ref)
"WHEN #{id} THEN #{index}" variables = variables.group_by(&:group_id)
end.join("\n") list_of_ids.reverse.map { |group| variables[group.id] }.compact.flatten
variables = Ci::GroupVariable
.where("group_id IN (#{list_of_ids.join(", ")})")
.order("CASE group_id #{order} END DESC")
project.protected_for?(ref) ? variables : variables.unprotected
end end
protected protected