debian-mirror-gitlab/app/finders/ci/variables_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
720 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Ci
class VariablesFinder
2021-04-29 21:17:54 +05:30
def initialize(resource, params)
@resource = resource
@params = params
2020-07-28 23:09:34 +05:30
raise ArgumentError, 'Please provide params[:key]' if params[:key].blank?
end
def execute
2021-04-29 21:17:54 +05:30
variables = resource.variables
2020-07-28 23:09:34 +05:30
variables = by_key(variables)
2021-04-29 21:17:54 +05:30
by_environment_scope(variables)
2020-07-28 23:09:34 +05:30
end
private
2021-04-29 21:17:54 +05:30
attr_reader :resource, :params
2020-07-28 23:09:34 +05:30
def by_key(variables)
variables.by_key(params[:key])
end
def by_environment_scope(variables)
environment_scope = params.dig(:filter, :environment_scope)
environment_scope.present? ? variables.by_environment_scope(environment_scope) : variables
end
end
end