Class: Pact::PactBroker::FetchPactURIsForVerification

Inherits:
Object
  • Object
show all
Includes:
PactSelectionDescription
Defined in:
lib/pact/pact_broker/fetch_pact_uris_for_verification.rb

Constant Summary collapse

PACTS_FOR_VERIFICATION_RELATION =
'pb:provider-pacts-for-verification'.freeze
PACTS_FOR_VERIFICATION_RELATION_BETA =
'beta:provider-pacts-for-verification'.freeze
PACTS =
'pacts'.freeze
HREF =
'href'.freeze
'_links'.freeze
SELF =
'self'.freeze
EMBEDDED =
'_embedded'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PactSelectionDescription

#pact_selection_description

Constructor Details

#initialize(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options, options = {}) ⇒ FetchPactURIsForVerification

Returns a new instance of FetchPactURIsForVerification.



26
27
28
29
30
31
32
33
34
35
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 26

def initialize(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options, options = {})
  @provider = provider
  @consumer_version_selectors = consumer_version_selectors || []
  @provider_version_branch = provider_version_branch
  @provider_version_tags = [*provider_version_tags]
  @http_client_options = http_client_options
  @broker_base_url = broker_base_url
  @http_client = Pact::Hal::HttpClient.new(http_client_options)
  @options = options
end

Instance Attribute Details

#broker_base_urlObject (readonly)

Returns the value of attribute broker_base_url.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def broker_base_url
  @broker_base_url
end

#consumer_version_selectorsObject (readonly)

Returns the value of attribute consumer_version_selectors.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def consumer_version_selectors
  @consumer_version_selectors
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def http_client
  @http_client
end

#http_client_optionsObject (readonly)

Returns the value of attribute http_client_options.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def http_client_options
  @http_client_options
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def options
  @options
end

#providerObject (readonly)

Returns the value of attribute provider.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def provider
  @provider
end

#provider_version_branchObject (readonly)

Returns the value of attribute provider_version_branch.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def provider_version_branch
  @provider_version_branch
end

#provider_version_tagsObject (readonly)

Returns the value of attribute provider_version_tags.



16
17
18
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 16

def provider_version_tags
  @provider_version_tags
end

Class Method Details

.call(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options, options = {}) ⇒ Object



37
38
39
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 37

def self.call(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options, options = {})
  new(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options, options).call
end

Instance Method Details

#callObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pact/pact_broker/fetch_pact_uris_for_verification.rb', line 41

def call
  handling_no_pacts_found do
    if index.can?(PACTS_FOR_VERIFICATION_RELATION) || index.can?(PACTS_FOR_VERIFICATION_RELATION_BETA)
      log_message
      pacts_for_verification
    else
      old_selectors = consumer_version_selectors.collect do | selector |
        { name: selector[:tag], all: !selector[:latest], fallback: selector[:fallbackTag]}
      end
      # Fall back to old method of fetching pacts
      FetchPacts.call(provider, old_selectors, broker_base_url, http_client_options)
    end
  end
end