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
Public Class Methods
# File lib/coverband/configuration.rb, line 50 def initialize reset end
Public Instance Methods
# 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
# File lib/coverband/configuration.rb, line 186 def all_root_patterns @all_root_patterns ||= all_root_paths.map { |path| /^#{path}/ }.freeze end
# File lib/coverband/configuration.rb, line 212 def api_key @api_key ||= ENV["COVERBAND_API_KEY"] end
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
# 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
# File lib/coverband/configuration.rb, line 224 def coverband_timeout @coverband_timeout ||= coverband_env == "development" ? 5 : 2 end
# File lib/coverband/configuration.rb, line 174 def current_root @current_root ||= File.expand_path(Coverband.configuration.root).freeze end
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
# File lib/coverband/configuration.rb, line 100 def logger @logger ||= if defined?(Rails.logger) && Rails.logger Rails.logger else Logger.new(STDOUT) end end
# 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
# File lib/coverband/configuration.rb, line 108 def password @password || ENV["COVERBAND_PASSWORD"] end
# File lib/coverband/configuration.rb, line 236 def process_type @process_type ||= ENV["PROCESS_TYPE"] || "unknown" end
# File lib/coverband/configuration.rb, line 208 def redis_url @redis_url ||= ENV["COVERBAND_REDIS_URL"] || ENV["REDIS_URL"] end
# File lib/coverband/configuration.rb, line 127 def reporting_wiggle @reporting_wiggle ||= 30 end
# 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
# File lib/coverband/configuration.rb, line 257 def s3_access_key_id puts "deprecated, s3 is no longer support" end
# File lib/coverband/configuration.rb, line 249 def s3_bucket puts "deprecated, s3 is no longer support" end
# File lib/coverband/configuration.rb, line 253 def s3_region puts "deprecated, s3 is no longer support" end
# File lib/coverband/configuration.rb, line 261 def s3_secret_access_key puts "deprecated, s3 is no longer support" end
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
# File lib/coverband/configuration.rb, line 240 def service? Coverband.coverband_service? || !api_key.nil? end
# File lib/coverband/configuration.rb, line 228 def service_dev_mode @service_dev_mode ||= ENV["COVERBAND_ENABLE_DEV_MODE"] || false end
# 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
# File lib/coverband/configuration.rb, line 232 def service_test_mode @service_dev_mode ||= ENV["COVERBAND_ENABLE_TEST_MODE"] || false end
# File lib/coverband/configuration.rb, line 216 def service_url @service_url ||= ENV["COVERBAND_URL"] || "https://coverband.io" end
# 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
# 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
# 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
# File lib/coverband/configuration.rb, line 265 def track_gems=(_value) puts "gem tracking is deprecated, setting this will be ignored" end
# File lib/coverband/configuration.rb, line 149 def track_views @track_views ||= service_disabled_dev_test_env? ? false : true end
Search Paths
# File lib/coverband/configuration.rb, line 156 def tracked_search_paths "#{Coverband.configuration.current_root}/{#{@search_paths.join(",")}}/**/*.{rb}" end
# 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
# File lib/coverband/configuration.rb, line 271 def redis_store_options {ttl: Coverband.configuration.redis_ttl, redis_namespace: Coverband.configuration.redis_namespace} end