Module: Pact::PactFile

Extended by:
PactFile
Included in:
PactFile
Defined in:
lib/pact/consumer_contract/consumer_contract.rb

Instance Method Summary collapse

Instance Method Details

#read(uri, options = {}) ⇒ Object



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

def read uri, options = {}
  pact = open(uri) { | file | file.read }
  if options[:save_pactfile_to_tmp]
    save_pactfile_to_tmp pact, ::File.basename(uri)
  end
  pact
rescue StandardError => e
  $stderr.puts "Error reading file from #{uri}"
  $stderr.puts "#{e.to_s} #{e.backtrace.join("\n")}"
  raise e
end

#save_pactfile_to_tmp(pact, name) ⇒ Object



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

def save_pactfile_to_tmp pact, name
  ::FileUtils.mkdir_p Pact.configuration.tmp_dir
  ::File.open(Pact.configuration.tmp_dir + "/#{name}", "w") { |file|  file << pact}
end