coverband 4.2.6 → 5.0.0.rc.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +26 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +5 -7
  5. data/Gemfile.rails4 +0 -3
  6. data/Gemfile.rails6 +0 -3
  7. data/README.md +24 -77
  8. data/Rakefile +17 -17
  9. data/changes.md +30 -28
  10. data/config.ru +1 -1
  11. data/coverband.gemspec +31 -34
  12. data/lib/alternative_coverband_patch.rb +5 -0
  13. data/lib/coverband.rb +68 -44
  14. data/lib/coverband/adapters/base.rb +17 -18
  15. data/lib/coverband/adapters/file_store.rb +38 -6
  16. data/lib/coverband/adapters/hash_redis_store.rb +24 -21
  17. data/lib/coverband/adapters/redis_store.rb +12 -12
  18. data/lib/coverband/adapters/stdout_store.rb +41 -0
  19. data/lib/coverband/adapters/web_service_store.rb +155 -0
  20. data/lib/coverband/at_exit.rb +1 -1
  21. data/lib/coverband/collectors/coverage.rb +15 -27
  22. data/lib/coverband/collectors/delta.rb +29 -9
  23. data/lib/coverband/collectors/view_tracker.rb +10 -10
  24. data/lib/coverband/collectors/view_tracker_service.rb +59 -0
  25. data/lib/coverband/configuration.rb +150 -113
  26. data/lib/coverband/integrations/background.rb +6 -6
  27. data/lib/coverband/integrations/rack_server_check.rb +3 -3
  28. data/lib/coverband/integrations/resque.rb +13 -1
  29. data/lib/coverband/reporters/base.rb +11 -12
  30. data/lib/coverband/reporters/console_report.rb +1 -1
  31. data/lib/coverband/reporters/html_report.rb +10 -30
  32. data/lib/coverband/reporters/web.rb +55 -50
  33. data/lib/coverband/utils/absolute_file_converter.rb +6 -6
  34. data/lib/coverband/utils/html_formatter.rb +32 -61
  35. data/lib/coverband/utils/railtie.rb +23 -6
  36. data/lib/coverband/utils/relative_file_converter.rb +2 -2
  37. data/lib/coverband/utils/result.rb +6 -11
  38. data/lib/coverband/utils/results.rb +0 -10
  39. data/lib/coverband/utils/source_file.rb +21 -30
  40. data/lib/coverband/utils/tasks.rb +8 -11
  41. data/lib/coverband/version.rb +1 -1
  42. data/public/application.js +0 -30
  43. data/test/benchmarks/benchmark.rake +97 -92
  44. data/test/benchmarks/dog.rb +1 -1
  45. data/test/benchmarks/init_rails.rake +4 -4
  46. data/test/coverband/adapters/base_test.rb +29 -30
  47. data/test/coverband/adapters/file_store_test.rb +19 -20
  48. data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
  49. data/test/coverband/adapters/redis_store_test.rb +26 -26
  50. data/test/coverband/adapters/web_service_store_test.rb +56 -0
  51. data/test/coverband/at_exit_test.rb +2 -2
  52. data/test/coverband/collectors/coverage_test.rb +33 -47
  53. data/test/coverband/collectors/delta_test.rb +52 -23
  54. data/test/coverband/collectors/view_tracker_test.rb +35 -35
  55. data/test/coverband/configuration_test.rb +61 -48
  56. data/test/coverband/coverband_test.rb +11 -11
  57. data/test/coverband/integrations/background_middleware_test.rb +10 -10
  58. data/test/coverband/integrations/background_test.rb +17 -5
  59. data/test/coverband/integrations/rack_server_check_test.rb +7 -7
  60. data/test/coverband/integrations/report_middleware_test.rb +9 -9
  61. data/test/coverband/integrations/resque_worker_test.rb +9 -9
  62. data/test/coverband/integrations/test_resque_job.rb +1 -1
  63. data/test/coverband/reporters/base_test.rb +9 -9
  64. data/test/coverband/reporters/console_test.rb +6 -6
  65. data/test/coverband/reporters/html_test.rb +36 -48
  66. data/test/coverband/reporters/web_test.rb +16 -18
  67. data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
  68. data/test/coverband/utils/file_hasher_test.rb +6 -12
  69. data/test/coverband/utils/file_list_test.rb +13 -13
  70. data/test/coverband/utils/html_formatter_test.rb +9 -23
  71. data/test/coverband/utils/lines_classifier_test.rb +29 -29
  72. data/test/coverband/utils/relative_file_converter_test.rb +13 -13
  73. data/test/coverband/utils/result_test.rb +18 -18
  74. data/test/coverband/utils/results_test.rb +17 -17
  75. data/test/coverband/utils/source_file_line_test.rb +46 -46
  76. data/test/coverband/utils/source_file_test.rb +38 -88
  77. data/test/dog.rb +1 -1
  78. data/test/fake_app/basic_rack.rb +2 -2
  79. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  80. data/test/fixtures/app/models/user.rb +1 -1
  81. data/test/fixtures/sample.rb +1 -1
  82. data/test/fixtures/utf-8.rb +0 -2
  83. data/test/forked/rails_full_stack_test.rb +24 -27
  84. data/test/forked/rails_rake_full_stack_test.rb +7 -26
  85. data/test/integration/full_stack_test.rb +11 -22
  86. data/test/jruby_check.rb +2 -3
  87. data/test/rails4_dummy/Rakefile +1 -1
  88. data/test/rails4_dummy/config.ru +1 -1
  89. data/test/rails4_dummy/config/application.rb +4 -4
  90. data/test/rails4_dummy/config/boot.rb +2 -2
  91. data/test/rails4_dummy/config/coverband.rb +1 -1
  92. data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
  93. data/test/rails4_dummy/config/environment.rb +1 -1
  94. data/test/rails4_dummy/config/routes.rb +2 -2
  95. data/test/rails5_dummy/Rakefile +1 -1
  96. data/test/rails5_dummy/config.ru +1 -1
  97. data/test/rails5_dummy/config/application.rb +3 -3
  98. data/test/rails5_dummy/config/coverband.rb +8 -8
  99. data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
  100. data/test/rails5_dummy/config/environment.rb +1 -1
  101. data/test/rails5_dummy/config/routes.rb +2 -2
  102. data/test/rails6_dummy/Rakefile +1 -1
  103. data/test/rails6_dummy/config.ru +1 -1
  104. data/test/rails6_dummy/config/application.rb +4 -4
  105. data/test/rails6_dummy/config/boot.rb +2 -2
  106. data/test/rails6_dummy/config/coverband.rb +1 -1
  107. data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
  108. data/test/rails6_dummy/config/environment.rb +1 -1
  109. data/test/rails6_dummy/config/routes.rb +2 -2
  110. data/test/rails_test_helper.rb +11 -11
  111. data/test/test_helper.rb +44 -34
  112. data/test/unique_files.rb +10 -10
  113. data/views/layout.erb +2 -12
  114. metadata +29 -34
  115. data/.rubocop.yml +0 -84
  116. data/lib/coverband/integrations/bundler.rb +0 -8
  117. data/lib/coverband/utils/file_groups.rb +0 -53
  118. data/lib/coverband/utils/gem_list.rb +0 -31
  119. data/lib/coverband/utils/s3_report.rb +0 -105
  120. data/test/coverband/utils/file_groups_test.rb +0 -61
  121. data/test/coverband/utils/gem_list_test.rb +0 -48
  122. data/test/coverband/utils/s3_report_test.rb +0 -44
  123. data/views/gem_list.erb +0 -63
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coverband
4
+ COVERBAND_ALTERNATE_PATCH = true
5
+ end
@@ -1,42 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'json'
5
- require 'redis'
6
- require 'coverband/version'
7
- require 'coverband/at_exit'
8
- require 'coverband/configuration'
9
- require 'coverband/utils/relative_file_converter'
10
- require 'coverband/utils/absolute_file_converter'
11
- require 'coverband/adapters/base'
12
- require 'coverband/adapters/redis_store'
13
- require 'coverband/adapters/hash_redis_store'
14
- require 'coverband/adapters/file_store'
15
- require 'coverband/utils/file_hasher'
16
- require 'coverband/utils/s3_report'
17
- require 'coverband/utils/html_formatter'
18
- require 'coverband/utils/result'
19
- require 'coverband/utils/file_list'
20
- require 'coverband/utils/gem_list'
21
- require 'coverband/utils/source_file'
22
- require 'coverband/utils/file_groups'
23
- require 'coverband/utils/lines_classifier'
24
- require 'coverband/utils/results'
25
- require 'coverband/collectors/coverage'
26
- require 'coverband/collectors/view_tracker'
27
- require 'coverband/reporters/base'
28
- require 'coverband/reporters/html_report'
29
- require 'coverband/reporters/console_report'
30
- require 'coverband/reporters/web'
31
- require 'coverband/integrations/background'
32
- require 'coverband/integrations/background_middleware'
33
- require 'coverband/integrations/rack_server_check'
34
-
35
- Coverband::Adapters::RedisStore = Coverband::Adapters::HashRedisStore if ENV['COVERBAND_HASH_REDIS_STORE']
3
+ require "logger"
4
+ require "json"
5
+ require "redis"
6
+ require "coverband/version"
7
+ require "coverband/at_exit"
8
+ require "coverband/configuration"
9
+ require "coverband/utils/relative_file_converter"
10
+ require "coverband/utils/absolute_file_converter"
11
+ require "coverband/adapters/base"
12
+ require "coverband/adapters/redis_store"
13
+ require "coverband/adapters/hash_redis_store"
14
+ require "coverband/adapters/file_store"
15
+ require "coverband/adapters/stdout_store"
16
+ require "coverband/utils/file_hasher"
17
+ require "coverband/collectors/coverage"
18
+ require "coverband/collectors/view_tracker"
19
+ require "coverband/collectors/view_tracker_service"
20
+ require "coverband/reporters/base"
21
+ require "coverband/reporters/console_report"
22
+ require "coverband/integrations/background"
23
+ require "coverband/integrations/background_middleware"
24
+ require "coverband/integrations/rack_server_check"
25
+
26
+ Coverband::Adapters::RedisStore = Coverband::Adapters::HashRedisStore if ENV["COVERBAND_HASH_REDIS_STORE"]
36
27
 
37
28
  module Coverband
38
29
  @@configured = false
39
- CONFIG_FILE = './config/coverband.rb'
30
+ SERVICE_CONFIG = "./config/coverband_service.rb"
31
+ CONFIG_FILE = "./config/coverband.rb"
40
32
  RUNTIME_TYPE = :runtime
41
33
  EAGER_TYPE = :eager_loading
42
34
  MERGED_TYPE = :merged
@@ -44,19 +36,27 @@ module Coverband
44
36
  ALL_TYPES = TYPES + [:merged]
45
37
 
46
38
  def self.configure(file = nil)
47
- configuration_file = file || ENV.fetch('COVERBAND_CONFIG', CONFIG_FILE)
39
+ configuration_file = file || ENV["COVERBAND_CONFIG"]
40
+ if configuration_file.nil?
41
+ configuration_file = coverband_service? ? SERVICE_CONFIG : CONFIG_FILE
42
+ end
43
+
48
44
  configuration
49
45
  if block_given?
50
46
  yield(configuration)
51
47
  elsif File.exist?(configuration_file)
52
48
  load configuration_file
53
49
  else
54
- configuration.logger.debug('using default configuration')
50
+ configuration.logger.debug("using default configuration")
55
51
  end
56
52
  @@configured = true
57
53
  coverage_instance.reset_instance
58
54
  end
59
55
 
56
+ def self.coverband_service?
57
+ !!File.exist?(SERVICE_CONFIG)
58
+ end
59
+
60
60
  def self.configured?
61
61
  @@configured
62
62
  end
@@ -98,19 +98,43 @@ module Coverband
98
98
  private_class_method def self.coverage_instance
99
99
  Coverband::Collectors::Coverage.instance
100
100
  end
101
- unless ENV['COVERBAND_DISABLE_AUTO_START']
101
+
102
+ unless ENV["COVERBAND_DISABLE_AUTO_START"]
102
103
  begin
103
- require 'coverband/utils/jruby_ext' if RUBY_PLATFORM == 'java'
104
104
  # Coverband should be setup as early as possible
105
105
  # to capture usage of things loaded by initializers or other Rails engines
106
- configure
107
- start
108
- require 'coverband/utils/railtie' if defined? ::Rails::Railtie
109
- require 'coverband/integrations/resque' if defined? ::Resque
110
- require 'coverband/integrations/bundler' if defined? ::Bundler
106
+ # but after gems are loaded to avoid slowing down gem usage
107
+ # best is in application.rb after the bundler line but we get close with Railtie
108
+ if defined? ::Rails::Railtie
109
+ require "coverband/utils/railtie"
110
+ else
111
+ configure
112
+ start
113
+ end
114
+ require "coverband/integrations/resque" if defined? ::Resque
111
115
  rescue Redis::CannotConnectError => error
112
116
  Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
113
- Coverband.configuration.logger.info 'If this is a setup task like assets:precompile feel free to ignore'
117
+ Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
118
+ end
119
+ end
120
+
121
+ module Reporters
122
+ class Web
123
+ ###
124
+ # NOTE: if the user doesn't setup the webreporter
125
+ # we don't need any of the below files loaded or using memory
126
+ ###
127
+ def initialize
128
+ require "coverband/reporters/web"
129
+ require "coverband/utils/html_formatter"
130
+ require "coverband/utils/result"
131
+ require "coverband/utils/file_list"
132
+ require "coverband/utils/source_file"
133
+ require "coverband/utils/lines_classifier"
134
+ require "coverband/utils/results"
135
+ require "coverband/reporters/html_report"
136
+ init_web
137
+ end
114
138
  end
115
139
  end
116
140
  end
@@ -3,11 +3,11 @@
3
3
  module Coverband
4
4
  module Adapters
5
5
  class Base
6
- DATA_KEY = 'data'
7
- FIRST_UPDATED_KEY = 'first_updated_at'
8
- LAST_UPDATED_KEY = 'last_updated_at'
9
- FILE_HASH = 'file_hash'
10
- ABSTRACT_KEY = 'abstract'
6
+ DATA_KEY = "data"
7
+ FIRST_UPDATED_KEY = "first_updated_at"
8
+ LAST_UPDATED_KEY = "last_updated_at"
9
+ FILE_HASH = "file_hash"
10
+ ABSTRACT_KEY = "abstract"
11
11
 
12
12
  attr_accessor :type
13
13
 
@@ -40,11 +40,11 @@ module Coverband
40
40
  end
41
41
 
42
42
  def size_in_mib
43
- format('%<size>.2f', size: (size.to_f / 2**20))
43
+ format("%<size>.2f", size: (size.to_f / 2**20))
44
44
  end
45
45
 
46
46
  def save_report(_report)
47
- raise 'abstract'
47
+ raise "abstract"
48
48
  end
49
49
 
50
50
  def get_coverage_report
@@ -76,7 +76,7 @@ module Coverband
76
76
  runtime_data = coverage(Coverband::RUNTIME_TYPE)
77
77
  eager_data = coverage(Coverband::EAGER_TYPE)
78
78
  eager_data.values do |vals|
79
- vals['data'].map! { |line_coverage| line_coverage ? (0 - line_coverage) : line_coverage }
79
+ vals["data"].map! { |line_coverage| line_coverage ? (0 - line_coverage) : line_coverage }
80
80
  end
81
81
  merge_reports(runtime_data, eager_data, skip_expansion: true)
82
82
  end
@@ -112,19 +112,18 @@ module Coverband
112
112
  # transparently update from RUNTIME_TYPE = nil to RUNTIME_TYPE = :runtime
113
113
  # transparent update for format coveband_3_2
114
114
  old_report = coverage(nil, override_type: nil) if old_report.nil? && type == Coverband::RUNTIME_TYPE
115
-
116
115
  new_report = expand_report(new_report) unless options[:skip_expansion]
117
116
  keys = (new_report.keys + old_report.keys).uniq
118
117
  keys.each do |file|
119
118
  new_report[file] = if new_report[file] &&
120
- old_report[file] &&
121
- new_report[file][FILE_HASH] == old_report[file][FILE_HASH]
122
- merge_expanded_data(new_report[file], old_report[file])
123
- elsif new_report[file]
124
- new_report[file]
125
- else
126
- old_report[file]
127
- end
119
+ old_report[file] &&
120
+ new_report[file][FILE_HASH] == old_report[file][FILE_HASH]
121
+ merge_expanded_data(new_report[file], old_report[file])
122
+ elsif new_report[file]
123
+ new_report[file]
124
+ else
125
+ old_report[file]
126
+ end
128
127
  end
129
128
  new_report
130
129
  end
@@ -145,7 +144,7 @@ module Coverband
145
144
  elsif Coverband.configuration.simulate_oneshot_lines_coverage
146
145
  latest.map.with_index { |v, i| (v + original[i] >= 1 ? 1 : 0) if v && original[i] }
147
146
  else
148
- latest.map.with_index { |v, i| (v && original[i]) ? v + original[i] : nil }
147
+ latest.map.with_index { |v, i| v && original[i] ? v + original[i] : nil }
149
148
  end
150
149
  end
151
150
  end
@@ -3,14 +3,38 @@
3
3
  module Coverband
4
4
  module Adapters
5
5
  ###
6
- # FilesStore store a merged coverage file to local disk
7
- # Generally this is for testing and development
8
- # Not recommended for production deployment
6
+ # FileStore store a merged coverage file to local disk
7
+ #
8
+ # Notes: Concurrency
9
+ # * threadsafe as the caller to save_report uses @semaphore.synchronize
10
+ # * file access process safe as each file written per process PID
11
+ #
12
+ # Usage:
13
+ # config.store = Coverband::Adapters::FileStore.new('log/coverage.log')
14
+ #
15
+ # View Reports:
16
+ # Using this assumes you are syncing the coverage files
17
+ # to some shared storage that is accessable outside of the production server
18
+ # download files to a system where you want to view the reports..
19
+ # When viewing coverage from the filestore adapter it merges all coverage
20
+ # files matching the path pattern, in this case `log/coverage.log.*`
21
+ #
22
+ # run: `bundle exec rake coverband:coverage_server`
23
+ # open http://localhost:1022/
24
+ #
25
+ # one could also build a report via code, the output is suitable to feed into SimpleCov
26
+ #
27
+ # ```
28
+ # coverband.configuration.store.merge_mode = true
29
+ # coverband.configuration.store.coverage
30
+ # ```
9
31
  ###
10
32
  class FileStore < Base
33
+ attr_accessor :merge_mode
11
34
  def initialize(path, _opts = {})
12
35
  super()
13
- @path = path
36
+ @path = "#{path}.#{::Process.pid}"
37
+ @merge_mode = false
14
38
 
15
39
  config_dir = File.dirname(@path)
16
40
  Dir.mkdir config_dir unless File.exist?(config_dir)
@@ -29,17 +53,25 @@ module Coverband
29
53
  end
30
54
 
31
55
  def coverage(_local_type = nil)
32
- if File.exist?(path)
56
+ if merge_mode
57
+ data = {}
58
+ Dir[path.sub(/\.\d+/, ".*")].each do |path|
59
+ data = merge_reports(data, JSON.parse(File.read(path)), skip_expansion: true)
60
+ end
61
+ data
62
+ elsif File.exist?(path)
33
63
  JSON.parse(File.read(path))
34
64
  else
35
65
  {}
36
66
  end
67
+ rescue Errno::ENOENT
68
+ {}
37
69
  end
38
70
 
39
71
  def save_report(report)
40
72
  data = report.dup
41
73
  data = merge_reports(data, coverage)
42
- File.open(path, 'w') { |f| f.write(data.to_json) }
74
+ File.write(path, JSON.dump(data))
43
75
  end
44
76
 
45
77
  def raw_store
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'securerandom'
3
+ require "securerandom"
4
4
 
5
5
  module Coverband
6
6
  module Adapters
7
7
  class HashRedisStore < Base
8
- FILE_KEY = 'file'
9
- FILE_LENGTH_KEY = 'file_length'
8
+ FILE_KEY = "file"
9
+ FILE_LENGTH_KEY = "file_length"
10
10
  META_DATA_KEYS = [DATA_KEY, FIRST_UPDATED_KEY, LAST_UPDATED_KEY, FILE_HASH].freeze
11
11
  ###
12
12
  # This key isn't related to the coverband version, but to the interal format
13
13
  # used to store data to redis. It is changed only when breaking changes to our
14
14
  # redis format are required.
15
15
  ###
16
- REDIS_STORAGE_FORMAT_VERSION = 'coverband_hash_3_3'
16
+ REDIS_STORAGE_FORMAT_VERSION = "coverband_hash_3_3"
17
17
 
18
18
  JSON_PAYLOAD_EXPIRATION = 5 * 60
19
19
 
@@ -25,14 +25,17 @@ module Coverband
25
25
  @save_report_batch_size = opts[:save_report_batch_size] || 100
26
26
  @format_version = REDIS_STORAGE_FORMAT_VERSION
27
27
  @redis = redis
28
- raise 'HashRedisStore requires redis >= 2.6.0' unless supported?
28
+ raise "HashRedisStore requires redis >= 2.6.0" unless supported?
29
29
 
30
30
  @ttl = opts[:ttl]
31
31
  @relative_file_converter = opts[:relative_file_converter] || Utils::RelativeFileConverter
32
32
  end
33
33
 
34
34
  def supported?
35
- Gem::Version.new(@redis.info['redis_version']) >= Gem::Version.new('2.6.0')
35
+ Gem::Version.new(@redis.info["redis_version"]) >= Gem::Version.new("2.6.0")
36
+ rescue Redis::CannotConnectError => error
37
+ Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
38
+ Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
36
39
  end
37
40
 
38
41
  def clear!
@@ -60,7 +63,7 @@ module Coverband
60
63
  updated_time = type == Coverband::EAGER_TYPE ? nil : report_time
61
64
  keys = []
62
65
  report.each_slice(@save_report_batch_size) do |slice|
63
- files_data = slice.map do |(file, data)|
66
+ files_data = slice.map { |(file, data)|
64
67
  relative_file = @relative_file_converter.convert(file)
65
68
  file_hash = file_hash(relative_file)
66
69
  key = key(relative_file, file_hash: file_hash)
@@ -73,11 +76,11 @@ module Coverband
73
76
  report_time: report_time,
74
77
  updated_time: updated_time
75
78
  )
76
- end
79
+ }
77
80
  next unless files_data.any?
78
81
 
79
- arguments_key = [@redis_namespace, SecureRandom.uuid].compact.join('.')
80
- @redis.set(arguments_key, { ttl: @ttl, files_data: files_data }.to_json, ex: JSON_PAYLOAD_EXPIRATION)
82
+ arguments_key = [@redis_namespace, SecureRandom.uuid].compact.join(".")
83
+ @redis.set(arguments_key, {ttl: @ttl, files_data: files_data}.to_json, ex: JSON_PAYLOAD_EXPIRATION)
81
84
  @redis.evalsha(hash_incr_script, [arguments_key])
82
85
  end
83
86
  @redis.sadd(files_key, keys) if keys.any?
@@ -85,11 +88,11 @@ module Coverband
85
88
 
86
89
  def coverage(local_type = nil)
87
90
  files_set = files_set(local_type)
88
- @redis.pipelined do
91
+ @redis.pipelined {
89
92
  files_set.map do |key|
90
93
  @redis.hgetall(key)
91
94
  end
92
- end.each_with_object({}) do |data_from_redis, hash|
95
+ }.each_with_object({}) do |data_from_redis, hash|
93
96
  add_coverage_for_file(data_from_redis, hash)
94
97
  end
95
98
  end
@@ -99,11 +102,11 @@ module Coverband
99
102
  end
100
103
 
101
104
  def size
102
- 'not available'
105
+ "not available"
103
106
  end
104
107
 
105
108
  def size_in_mib
106
- 'not available'
109
+ "not available"
107
110
  end
108
111
 
109
112
  private
@@ -115,7 +118,7 @@ module Coverband
115
118
  return unless file_hash(file) == data_from_redis[FILE_HASH]
116
119
 
117
120
  data = coverage_data_from_redis(data_from_redis)
118
- hash[file] = data_from_redis.select { |meta_data_key, _value| META_DATA_KEYS.include?(meta_data_key) }.merge!('data' => data)
121
+ hash[file] = data_from_redis.select { |meta_data_key, _value| META_DATA_KEYS.include?(meta_data_key) }.merge!("data" => data)
119
122
  hash[file][LAST_UPDATED_KEY] = hash[file][LAST_UPDATED_KEY].blank? ? nil : hash[file][LAST_UPDATED_KEY].to_i
120
123
  hash[file].merge!(LAST_UPDATED_KEY => hash[file][LAST_UPDATED_KEY], FIRST_UPDATED_KEY => hash[file][FIRST_UPDATED_KEY].to_i)
121
124
  end
@@ -129,9 +132,9 @@ module Coverband
129
132
  end
130
133
 
131
134
  def script_input(key:, file:, file_hash:, data:, report_time:, updated_time:)
132
- coverage_data = data.each_with_index.each_with_object({}) do |(coverage, index), hash|
135
+ coverage_data = data.each_with_index.each_with_object({}) { |(coverage, index), hash|
133
136
  hash[index] = coverage if coverage
134
- end
137
+ }
135
138
  meta = {
136
139
  first_updated_at: report_time,
137
140
  file: file,
@@ -153,8 +156,8 @@ module Coverband
153
156
 
154
157
  def lua_script_content
155
158
  File.read(File.join(
156
- File.dirname(__FILE__), '../../../lua/lib/persist-coverage.lua'
157
- ))
159
+ File.dirname(__FILE__), "../../../lua/lib/persist-coverage.lua"
160
+ ))
158
161
  end
159
162
 
160
163
  def values_from_redis(local_type, files)
@@ -178,12 +181,12 @@ module Coverband
178
181
  end
179
182
 
180
183
  def key(file, local_type = nil, file_hash:)
181
- [key_prefix(local_type), file, file_hash].join('.')
184
+ [key_prefix(local_type), file, file_hash].join(".")
182
185
  end
183
186
 
184
187
  def key_prefix(local_type = nil)
185
188
  local_type ||= type
186
- [@format_version, @redis_namespace, local_type].compact.join('.')
189
+ [@format_version, @redis_namespace, local_type].compact.join(".")
187
190
  end
188
191
  end
189
192
  end
@@ -11,19 +11,19 @@ module Coverband
11
11
  # used to store data to redis. It is changed only when breaking changes to our
12
12
  # redis format are required.
13
13
  ###
14
- REDIS_STORAGE_FORMAT_VERSION = 'coverband_3_2'
14
+ REDIS_STORAGE_FORMAT_VERSION = "coverband_3_2"
15
15
 
16
16
  attr_reader :redis_namespace
17
17
 
18
18
  def initialize(redis, opts = {})
19
19
  super()
20
- @redis = redis
21
- @ttl = opts[:ttl]
20
+ @redis = redis
21
+ @ttl = opts[:ttl]
22
22
  @redis_namespace = opts[:redis_namespace]
23
- @format_version = REDIS_STORAGE_FORMAT_VERSION
24
- @keys = {}
23
+ @format_version = REDIS_STORAGE_FORMAT_VERSION
24
+ @keys = {}
25
25
  Coverband::TYPES.each do |type|
26
- @keys[type] = [@format_version, @redis_namespace, type].compact.join('.')
26
+ @keys[type] = [@format_version, @redis_namespace, type].compact.join(".")
27
27
  end
28
28
  end
29
29
 
@@ -54,15 +54,15 @@ module Coverband
54
54
  ###
55
55
  def migrate!
56
56
  reset_base_key
57
- @format_version = 'coverband3_1'
57
+ @format_version = "coverband3_1"
58
58
  previous_data = coverage
59
59
  if previous_data.empty?
60
- puts 'no previous data to migrate found'
60
+ puts "no previous data to migrate found"
61
61
  exit 0
62
62
  end
63
- relative_path_report = previous_data.each_with_object({}) do |(key, vals), fixed_report|
63
+ relative_path_report = previous_data.each_with_object({}) { |(key, vals), fixed_report|
64
64
  fixed_report[Utils::RelativeFileConverter.convert(key)] = vals
65
- end
65
+ }
66
66
  clear!
67
67
  reset_base_key
68
68
  @format_version = REDIS_STORAGE_FORMAT_VERSION
@@ -78,7 +78,7 @@ module Coverband
78
78
  local_type ||= opts.key?(:override_type) ? opts[:override_type] : type
79
79
  data = redis.get type_base_key(local_type)
80
80
  data = data ? JSON.parse(data) : {}
81
- data.delete_if { |file_path, file_data| file_hash(file_path) != file_data['file_hash'] } unless opts[:skip_hash_check]
81
+ data.delete_if { |file_path, file_data| file_hash(file_path) != file_data["file_hash"] } unless opts[:skip_hash_check]
82
82
  data
83
83
  end
84
84
 
@@ -105,7 +105,7 @@ module Coverband
105
105
  end
106
106
 
107
107
  def base_key
108
- @base_key ||= [@format_version, @redis_namespace, type].compact.join('.')
108
+ @base_key ||= [@format_version, @redis_namespace, type].compact.join(".")
109
109
  end
110
110
 
111
111
  def type_base_key(local_type)