Class: Pact::ConsumerContractWriter

Inherits:
Object
  • Object
show all
Includes:
ActiveSupportSupport, FileName, PactFile
Defined in:
lib/pact/consumer_contract/consumer_contract_writer.rb

Constant Summary collapse

DEFAULT_PACT_SPECIFICATION_VERSION =
'2.0.0'

Instance Method Summary collapse

Constructor Details

#initialize(consumer_contract_details, logger) ⇒ ConsumerContractWriter

Returns a new instance of ConsumerContractWriter.



22
23
24
25
26
27
28
29
30
31
# File 'lib/pact/consumer_contract/consumer_contract_writer.rb', line 22

def initialize consumer_contract_details, logger
  @logger = logger
  @consumer_contract_details = consumer_contract_details
  @pactfile_write_mode = (consumer_contract_details[:pactfile_write_mode] || :overwrite).to_sym
  @interactions = consumer_contract_details.fetch(:interactions)
  @pact_specification_version = (consumer_contract_details[:pact_specification_version] || DEFAULT_PACT_SPECIFICATION_VERSION).to_s
  @consumer_contract_decorator_class = consumer_contract_details[:consumer_contract_decorator_class] || Pact::ConsumerContractDecorator
  @error_stream = consumer_contract_details[:error_stream] || Pact.configuration.error_stream
  @output_stream = consumer_contract_details[:output_stream] || Pact.configuration.output_stream
end

Instance Method Details

#can_write?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/pact/consumer_contract/consumer_contract_writer.rb', line 45

def can_write?
  consumer_name && provider_name && consumer_contract_details[:pact_dir]
end

#consumer_contractObject



33
34
35
36
37
38
# File 'lib/pact/consumer_contract/consumer_contract_writer.rb', line 33

def consumer_contract
  @consumer_contract ||= Pact::ConsumerContract.new(
    consumer: ServiceConsumer.new(name: consumer_contract_details[:consumer][:name]),
    provider: ServiceProvider.new(name: consumer_contract_details[:provider][:name]),
    interactions: interactions_for_new_consumer_contract)
end

#writeObject



40
41
42
43
# File 'lib/pact/consumer_contract/consumer_contract_writer.rb', line 40

def write
  update_pactfile_if_needed
  pact_json
end