Skip to content

Commit

Permalink
improved loading coverage vs when we configure coverband
Browse files Browse the repository at this point in the history
  • Loading branch information
danmayer committed Aug 9, 2020
1 parent 78a1da3 commit 0ca04a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/coverband.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/coverband/configuration.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/utils/railtie.rb
Expand Up @@ -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!
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/version.rb
Expand Up @@ -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

0 comments on commit 0ca04a4

Please sign in to comment.