Sha256: 824d4de11352e3994416bac72bfee3b160cba12018e3efbeb1a6e6822fe74616

Contents?: true

Size: 1.73 KB

Versions: 11

Compression:

Stored size: 1.73 KB

Contents

require 'pact/shared/dsl'
require 'pact/provider/world'
require 'pact/pact_broker/fetch_pacts'
require 'pact/errors'

module Pact
  module Provider
    module Configuration
      class PactVerificationFromBroker

        extend Pact::DSL

        # If user declares a variable with the same name as one of these attributes
        # in parent scope, it will clash with these ones,
        # so put an underscore in front of the name to be safer.

        attr_accessor :_provider_name, :_pact_broker_base_url, :_consumer_version_tags, :_basic_auth_options, :_verbose

        def initialize(provider_name)
          @_provider_name = provider_name
          @_consumer_version_tags = []
          @_verbose = false
        end

        dsl do
          def pact_broker_base_url pact_broker_base_url, basic_auth_options = {}
            self._pact_broker_base_url = pact_broker_base_url
            self._basic_auth_options = basic_auth_options
          end

          def consumer_version_tags consumer_version_tags
            self._consumer_version_tags = *consumer_version_tags
          end

          def verbose verbose
            self._verbose = verbose
          end
        end

        def finalize
          validate
          create_pact_verification
        end

        private

        def create_pact_verification
          fetch_pacts = Pact::PactBroker::FetchPacts.new(_provider_name, _consumer_version_tags, _pact_broker_base_url, _basic_auth_options.merge(verbose: _verbose))
          Pact.provider_world.add_pact_uri_source fetch_pacts
        end

        def validate
          raise Pact::Error.new("Please provide a pact_broker_base_url from which to retrieve the pacts") unless _pact_broker_base_url
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pact-1.41.2 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.41.1 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.41.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.40.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.39.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.38.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.37.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.36.2 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.36.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.34.0 lib/pact/provider/configuration/pact_verification_from_broker.rb
pact-1.33.2 lib/pact/provider/configuration/pact_verification_from_broker.rb