Module: Pact::PactFile
- Extended by:
- PactFile
- Included in:
- ConsumerContract, PactFile
- Defined in:
- lib/pact/consumer_contract/pact_file.rb
Defined Under Namespace
Classes: HttpError
Constant Summary collapse
- OPEN_TIMEOUT =
5- READ_TIMEOUT =
5- RETRY_LIMIT =
3
Instance Method Summary collapse
- #read(uri, options = {}) ⇒ Object
- #render_pact(uri_string, options) ⇒ Object
- #save_pactfile_to_tmp(pact, name) ⇒ Object
Instance Method Details
#read(uri, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pact/consumer_contract/pact_file.rb', line 20 def read uri, = {} uri_string = uri.to_s pact = render_pact(uri_string, ) if [:save_pactfile_to_tmp] save_pactfile_to_tmp pact, ::File.basename(uri_string) end pact rescue StandardError => e $stderr.puts "Error reading file from #{uri}" $stderr.puts "#{e.to_s} #{e.backtrace.join("\n")}" raise e end |
#render_pact(uri_string, options) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/pact/consumer_contract/pact_file.rb', line 38 def render_pact(uri_string, ) uri_obj = URI(uri_string) if uri_obj.userinfo [:username] = uri_obj.user unless [:username] [:password] = uri_obj.password unless [:password] end get(uri_obj, ) end |
#save_pactfile_to_tmp(pact, name) ⇒ Object
33 34 35 36 |
# File 'lib/pact/consumer_contract/pact_file.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 |