From 0ca04a46a0569a8b24c05f8cc719a557d83f45f1 Mon Sep 17 00:00:00 2001 From: Dan Mayer Date: Sun, 9 Aug 2020 14:57:12 -0600 Subject: [PATCH] improved loading coverage vs when we configure coverband --- lib/coverband.rb | 8 +++++++- lib/coverband/configuration.rb | 6 +++++- lib/coverband/utils/railtie.rb | 2 +- lib/coverband/version.rb | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/coverband.rb b/lib/coverband.rb index 3f2a696d..20be00c9 100644 --- a/lib/coverband.rb +++ b/lib/coverband.rb @@ -26,6 +26,7 @@ module Coverband @@configured = false + SERVICE_CONFIG = "./config/coverband_service.rb" CONFIG_FILE = "./config/coverband.rb" RUNTIME_TYPE = :runtime EAGER_TYPE = :eager_loading @@ -34,7 +35,11 @@ module Coverband ALL_TYPES = TYPES + [:merged] def self.configure(file = nil) - configuration_file = file || ENV.fetch("COVERBAND_CONFIG", CONFIG_FILE) + configuration_file = file || ENV["COVERBAND_CONFIG"] + if configuration_file.nil? + configuration_file = File.exists?(SERVICE_CONFIG) ? SERVICE_CONFIG : CONFIG_FILE + end + configuration if block_given? yield(configuration) @@ -88,6 +93,7 @@ def self.runtime_coverage! private_class_method def self.coverage_instance Coverband::Collectors::Coverage.instance end + unless ENV["COVERBAND_DISABLE_AUTO_START"] begin # Coverband should be setup as early as possible diff --git a/lib/coverband/configuration.rb b/lib/coverband/configuration.rb index c5d7d2ac..78c18933 100644 --- a/lib/coverband/configuration.rb +++ b/lib/coverband/configuration.rb @@ -9,7 +9,7 @@ class Configuration :background_reporting_sleep_seconds, :test_env, :web_enable_clear, :gem_details, :web_debug, :report_on_exit, :simulate_oneshot_lines_coverage, :track_views, :view_tracker, - :reporting_wiggle + :reporting_wiggle, :api_key attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id, :s3_secret_access_key, :password @@ -189,6 +189,10 @@ def one_shot_coverage_implemented_in_ruby_version? Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0") end + def api_key + ENV['COVERBAND_API_KEY'] || Coverband.configuration.api_key + end + private def redis_url diff --git a/lib/coverband/utils/railtie.rb b/lib/coverband/utils/railtie.rb index a18a1b49..6438d844 100644 --- a/lib/coverband/utils/railtie.rb +++ b/lib/coverband/utils/railtie.rb @@ -30,6 +30,7 @@ class Railtie < Rails::Railtie config.after_initialize do unless Coverband.tasks_to_ignore? + Coverband.configure Coverband.eager_loading_coverage! Coverband.report_coverage Coverband.runtime_coverage! @@ -39,7 +40,6 @@ class Railtie < Rails::Railtie config.before_configuration do unless ENV["COVERBAND_DISABLE_AUTO_START"] begin - Coverband.configure Coverband.start rescue Redis::CannotConnectError => error Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured" diff --git a/lib/coverband/version.rb b/lib/coverband/version.rb index 7375089c..c4ec102a 100644 --- a/lib/coverband/version.rb +++ b/lib/coverband/version.rb @@ -5,5 +5,5 @@ # use format '4.2.1.rc.1' ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3 ### module Coverband - VERSION = "5.0.0.rc.3" + VERSION = "5.0.0.rc.4" end