lib/coverband-service-client.rb in coverband-service-client-0.0.9 vs lib/coverband-service-client.rb in coverband-service-client-0.0.10

- old
+ new

@@ -1,7 +1,9 @@ # frozen_string_literal: true +COVERBAND_ORIGINAL_START = ENV['COVERBAND_DISABLE_AUTO_START'] +ENV['COVERBAND_DISABLE_AUTO_START'] = 'true' require 'coverband' require 'coverband/service/client/version' require 'securerandom' module Coverband @@ -20,11 +22,11 @@ if service_disabled_dev_test_env? def self.report_coverage # for now disable coverband reporting in test & dev env by default if Coverband.configuration.verbose - puts "Coverband: disabled for #{COVERBAND_ENV}, set COVERBAND_ENABLE_DEV_MODE or COVERBAND_ENABLE_TEST_MODE to enable" + puts "Coverband: disabled for #{COVERBAND_ENV}, set COVERBAND_ENABLE_DEV_MODE or COVERBAND_ENABLE_TEST_MODE to enable" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end end end module Adapters @@ -114,17 +116,16 @@ if api_key.nil? puts "Coverband: Error: no Coverband API key was found!" end uri = URI("#{coverband_url}/api/collector") - logger&.info "Coverband: saving #{uri}" if Coverband.configuration.verbose req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => api_key) req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json - logger&.info "Coverband: saving #{req.body}" if Coverband.configuration.verbose + logger&.info "Coverband: saving (#{uri}) #{req.body}" if Coverband.configuration.verbose res = Net::HTTP.start( uri.hostname, uri.port, open_timeout: COVERBAND_TIMEOUT, read_timeout: COVERBAND_TIMEOUT, @@ -132,11 +133,11 @@ use_ssl: uri.scheme == 'https' ) do |http| http.request(req) end rescue StandardError => e - puts "Coverband: Error while saving coverage #{e}" + logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end end end module Service @@ -166,11 +167,11 @@ end self.views_to_record = [] rescue StandardError => e # we don't want to raise errors if Coverband can't reach redis. # This is a nice to have not a bring the system down - logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}" + logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end private def logger @@ -194,11 +195,11 @@ req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(req) end rescue StandardError => e - puts "Coverband: Error while saving coverage #{e}" + logger&.error "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end end end end @@ -206,10 +207,11 @@ class Configuration attr_accessor :api_key end end +ENV['COVERBAND_DISABLE_AUTO_START'] = COVERBAND_ORIGINAL_START Coverband.configure do |config| # Use The Test Service Adapter config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL) # default to tracking views true @@ -232,9 +234,12 @@ end # NOTE: it is really hard to bypass / overload our config we should fix this in Coverband # this hopefully detects anyone that has both gems and was trying to configure Coverband themselves. if File.exist?('./config/coverband.rb') - puts "Warning: config/coverband.rb found, this overrides coverband service allowing one to setup open source Coverband" + puts "Warning: config/coverband.rb found, this overrides coverband service allowing one to setup open source Coverband" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end Coverband.configure('./config/coverband_service.rb') if File.exist?('./config/coverband_service.rb') +Coverband.start +require "coverband/utils/railtie" if defined? ::Rails::Railtie +require "coverband/integrations/resque" if defined? ::Resque