Class: PactBroker::Matrix::ParseCanIDeployQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/matrix/parse_can_i_deploy_query.rb

Class Method Summary collapse

Class Method Details

.call(params) ⇒ Object

rubocop: disable Metrics/CyclomaticComplexity



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
# File 'lib/pact_broker/matrix/parse_can_i_deploy_query.rb', line 8

def self.call params
  selector = PactBroker::Matrix::UnresolvedSelector.new
  options = {
    latestby: "cvp"
  }

  if params[:pacticipant].is_a?(String)
    selector.pacticipant_name = params[:pacticipant]
  end

  if params[:version].is_a?(String)
    selector.pacticipant_version_number = params[:version]
  end

  if params[:to].is_a?(String)
    options[:tag] = params[:to]
    options[:latest] = true
  end

  if params[:environment].is_a?(String)
    options[:environment_name] = params[:environment]
  end

  if params[:ignore].is_a?(Array)
    options[:ignore_selectors] = params[:ignore].collect do | param |
      if param.is_a?(String)
        PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: param)
      elsif param.is_a?(Hash) && param.key?(:pacticipant)
        PactBroker::Matrix::UnresolvedSelector.new({ pacticipant_name: param[:pacticipant], pacticipant_version_number: param[:version] }.compact)
      end
    end.compact
  else
    options[:ignore_selectors] = []
  end

  return [selector], options
end