class Coverband::Configuration

Constants

IGNORE_DEFAULTS

Heroku when building assets runs code from a dynamic directory /tmp was added to avoid coverage from /tmp/build directories during heroku asset compilation

IGNORE_TASKS

TODO: This is is brittle and not a great solution to avoid deploy time actions polluting the 'runtime' metrics

  • Perhaps detect heroku deployment ENV var opposed to tasks?

SKIPPED_SETTINGS
TRACKED_DEFAULT_PATHS

Add in missing files which were never loaded we need to know what all paths to check for unloaded files

Attributes

api_key[W]
background_reporting_enabled[RW]
background_reporting_sleep_seconds[W]
coverband_timeout[W]
gem_details[RW]
ignore[R]
logger[W]
password[W]
process_type[W]
redis_namespace[RW]
redis_ttl[RW]
redis_url[W]
report_on_exit[RW]
reporter[RW]
reporting_wiggle[W]
root[RW]
root_paths[RW]
s3_access_key_id[W]
s3_bucket[W]
s3_region[W]
s3_secret_access_key[W]
service_dev_mode[W]
service_test_mode[W]
service_url[W]
simulate_oneshot_lines_coverage[RW]
test_env[RW]
track_gems[R]
track_views[W]
use_oneshot_lines_coverage[R]
verbose[RW]
view_tracker[RW]
web_debug[RW]
web_enable_clear[RW]

Public Class Methods

new() click to toggle source
# File lib/coverband/configuration.rb, line 50
def initialize
  reset
end

Public Instance Methods

all_root_paths() click to toggle source
# File lib/coverband/configuration.rb, line 178
def all_root_paths
  return @all_root_paths if @all_root_paths

  @all_root_paths = Coverband.configuration.root_paths.dup
  @all_root_paths << "#{Coverband.configuration.current_root}/"
  @all_root_paths
end
all_root_patterns() click to toggle source
# File lib/coverband/configuration.rb, line 186
def all_root_patterns
  @all_root_patterns ||= all_root_paths.map { |path| /^#{path}/ }.freeze
end
api_key() click to toggle source
# File lib/coverband/configuration.rb, line 212
def api_key
  @api_key ||= ENV["COVERBAND_API_KEY"]
end
background_reporting_sleep_seconds() click to toggle source

The adjustments here either protect the redis or service from being overloaded the tradeoff being the delay in when reporting data is available if running your own redis increasing this number reduces load on the redis CPU

# File lib/coverband/configuration.rb, line 115
def background_reporting_sleep_seconds
  @background_reporting_sleep_seconds ||= if service?
    # default to 10m for service
    Coverband.configuration.coverband_env == "production" ? 600 : 60
  elsif store.is_a?(Coverband::Adapters::HashRedisStore)
    # Default to 5 minutes if using the hash redis store
    300
  else
    60
  end
end
coverband_env() click to toggle source
# File lib/coverband/configuration.rb, line 220
def coverband_env
  ENV["RACK_ENV"] || ENV["RAILS_ENV"] || (defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : "unknown")
end
coverband_timeout() click to toggle source
# File lib/coverband/configuration.rb, line 224
def coverband_timeout
  @coverband_timeout ||= coverband_env == "development" ? 5 : 2
end
current_root() click to toggle source
# File lib/coverband/configuration.rb, line 174
def current_root
  @current_root ||= File.expand_path(Coverband.configuration.root).freeze
end
ignore=(ignored_array) click to toggle source

Don't allow the ignore to override things like gem tracking

# File lib/coverband/configuration.rb, line 170
def ignore=(ignored_array)
  @ignore = (@ignore + ignored_array).uniq
end
logger() click to toggle source
# File lib/coverband/configuration.rb, line 100
def logger
  @logger ||= if defined?(Rails.logger) && Rails.logger
    Rails.logger
  else
    Logger.new(STDOUT)
  end
end
one_shot_coverage_implemented_in_ruby_version?() click to toggle source
# File lib/coverband/configuration.rb, line 204
def one_shot_coverage_implemented_in_ruby_version?
  Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
end
password() click to toggle source
# File lib/coverband/configuration.rb, line 108
def password
  @password || ENV["COVERBAND_PASSWORD"]
end
process_type() click to toggle source
# File lib/coverband/configuration.rb, line 236
def process_type
  @process_type ||= ENV["PROCESS_TYPE"] || "unknown"
end
redis_url() click to toggle source
# File lib/coverband/configuration.rb, line 208
def redis_url
  @redis_url ||= ENV["COVERBAND_REDIS_URL"] || ENV["REDIS_URL"]
end
reporting_wiggle() click to toggle source
# File lib/coverband/configuration.rb, line 127
def reporting_wiggle
  @reporting_wiggle ||= 30
end
reset() click to toggle source
# File lib/coverband/configuration.rb, line 54
def reset
  @root = Dir.pwd
  @root_paths = []
  @ignore = IGNORE_DEFAULTS.dup
  @search_paths = TRACKED_DEFAULT_PATHS.dup
  @verbose = false
  @reporter = "scov"
  @logger = nil
  @store = nil
  @background_reporting_enabled = true
  @background_reporting_sleep_seconds = nil
  @test_env = nil
  @web_enable_clear = false
  @track_views = true
  @view_tracker = nil
  @web_debug = false
  @report_on_exit = true
  @use_oneshot_lines_coverage = ENV["ONESHOT"] || false
  @simulate_oneshot_lines_coverage = ENV["SIMULATE_ONESHOT"] || false
  @current_root = nil
  @all_root_paths = nil
  @all_root_patterns = nil
  @password = nil

  # coverband service settings
  @api_key = nil
  @service_url = nil
  @coverband_timeout = nil
  @service_dev_mode = nil
  @service_test_mode = nil
  @proces_type = nil

  @redis_url = nil
  @redis_namespace = nil
  @redis_ttl = 2_592_000 # in seconds. Default is 30 days.
  @reporting_wiggle = nil

  # TODO: these are deprecated
  @s3_region = nil
  @s3_bucket = nil
  @s3_access_key_id = nil
  @s3_secret_access_key = nil
  @track_gems = false
  @gem_details = false
end
s3_access_key_id() click to toggle source
# File lib/coverband/configuration.rb, line 257
def s3_access_key_id
  puts "deprecated, s3 is no longer support"
end
s3_bucket() click to toggle source
# File lib/coverband/configuration.rb, line 249
def s3_bucket
  puts "deprecated, s3 is no longer support"
end
s3_region() click to toggle source
# File lib/coverband/configuration.rb, line 253
def s3_region
  puts "deprecated, s3 is no longer support"
end
s3_secret_access_key() click to toggle source
# File lib/coverband/configuration.rb, line 261
def s3_secret_access_key
  puts "deprecated, s3 is no longer support"
end
search_paths=(path_array) click to toggle source

Don't allow the to override defaults

# File lib/coverband/configuration.rb, line 163
def search_paths=(path_array)
  @search_paths = (@search_paths + path_array).uniq
end
service?() click to toggle source
# File lib/coverband/configuration.rb, line 240
def service?
  Coverband.coverband_service? || !api_key.nil?
end
service_dev_mode() click to toggle source
# File lib/coverband/configuration.rb, line 228
def service_dev_mode
  @service_dev_mode ||= ENV["COVERBAND_ENABLE_DEV_MODE"] || false
end
service_disabled_dev_test_env?() click to toggle source
# File lib/coverband/configuration.rb, line 244
def service_disabled_dev_test_env?
  (coverband_env == "test" && !Coverband.configuration.service_test_mode) ||
    (coverband_env == "development" && !Coverband.configuration.service_dev_mode)
end
service_test_mode() click to toggle source
# File lib/coverband/configuration.rb, line 232
def service_test_mode
  @service_dev_mode ||= ENV["COVERBAND_ENABLE_TEST_MODE"] || false
end
service_url() click to toggle source
# File lib/coverband/configuration.rb, line 216
def service_url
  @service_url ||= ENV["COVERBAND_URL"] || "https://coverband.io"
end
store() click to toggle source
# File lib/coverband/configuration.rb, line 131
def store
  @store ||= if service?
    raise "invalid configuration: unclear default store coverband expects either api_key or redis_url" if ENV["COVERBAND_REDIS_URL"]
    require "coverband/adapters/web_service_store"
    Coverband::Adapters::WebServiceStore.new(service_url)
  else
    Coverband::Adapters::RedisStore.new(Redis.new(url: redis_url), redis_store_options)
  end
end
store=(store) click to toggle source
# File lib/coverband/configuration.rb, line 141
def store=(store)
  raise "Pass in an instance of Coverband::Adapters" unless store.is_a?(Coverband::Adapters::Base)
  raise "invalid configuration: only coverband service expects an API Key" if api_key && store.class.to_s != "Coverband::Adapters::WebServiceStore"
  raise "invalid configuration: coverband service shouldn't have redis url set" if ENV["COVERBAND_REDIS_URL"] && store.class.to_s == "Coverband::Adapters::WebServiceStore"

  @store = store
end
to_h() click to toggle source
# File lib/coverband/configuration.rb, line 191
def to_h
  instance_variables
    .each_with_object({}) do |var, hash|
      hash[var.to_s.delete("@")] = instance_variable_get(var) unless SKIPPED_SETTINGS.include?(var.to_s)
    end
end
track_gems=(_value) click to toggle source
# File lib/coverband/configuration.rb, line 265
def track_gems=(_value)
  puts "gem tracking is deprecated, setting this will be ignored"
end
track_views() click to toggle source
# File lib/coverband/configuration.rb, line 149
def track_views
  @track_views ||= service_disabled_dev_test_env? ? false : true
end
tracked_search_paths() click to toggle source

Search Paths

# File lib/coverband/configuration.rb, line 156
def tracked_search_paths
  "#{Coverband.configuration.current_root}/{#{@search_paths.join(",")}}/**/*.{rb}"
end
use_oneshot_lines_coverage=(value) click to toggle source
# File lib/coverband/configuration.rb, line 198
def use_oneshot_lines_coverage=(value)
  raise(StandardError, "One shot line coverage is only available in ruby >= 2.6") unless one_shot_coverage_implemented_in_ruby_version? || !value

  @use_oneshot_lines_coverage = value
end

Private Instance Methods

redis_store_options() click to toggle source
# File lib/coverband/configuration.rb, line 271
def redis_store_options
  {ttl: Coverband.configuration.redis_ttl,
   redis_namespace: Coverband.configuration.redis_namespace}
end