coverband 4.2.5.rc.2 → 5.0.0.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +25 -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 +26 -30
  10. data/config.ru +1 -1
  11. data/coverband.gemspec +29 -34
  12. data/lib/alternative_coverband_patch.rb +5 -0
  13. data/lib/coverband.rb +55 -43
  14. data/lib/coverband/adapters/base.rb +17 -17
  15. data/lib/coverband/adapters/file_store.rb +2 -2
  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/at_exit.rb +1 -1
  19. data/lib/coverband/collectors/coverage.rb +15 -27
  20. data/lib/coverband/collectors/delta.rb +19 -9
  21. data/lib/coverband/collectors/view_tracker.rb +19 -11
  22. data/lib/coverband/configuration.rb +48 -84
  23. data/lib/coverband/integrations/background.rb +3 -3
  24. data/lib/coverband/integrations/rack_server_check.rb +3 -3
  25. data/lib/coverband/integrations/resque.rb +13 -1
  26. data/lib/coverband/reporters/base.rb +10 -10
  27. data/lib/coverband/reporters/console_report.rb +1 -1
  28. data/lib/coverband/reporters/html_report.rb +10 -30
  29. data/lib/coverband/reporters/web.rb +56 -49
  30. data/lib/coverband/utils/absolute_file_converter.rb +6 -6
  31. data/lib/coverband/utils/html_formatter.rb +32 -61
  32. data/lib/coverband/utils/railtie.rb +16 -4
  33. data/lib/coverband/utils/relative_file_converter.rb +2 -2
  34. data/lib/coverband/utils/result.rb +6 -11
  35. data/lib/coverband/utils/results.rb +0 -10
  36. data/lib/coverband/utils/source_file.rb +21 -30
  37. data/lib/coverband/utils/tasks.rb +7 -11
  38. data/lib/coverband/version.rb +1 -1
  39. data/public/application.js +0 -30
  40. data/test/benchmarks/benchmark.rake +97 -92
  41. data/test/benchmarks/dog.rb +1 -1
  42. data/test/benchmarks/init_rails.rake +4 -4
  43. data/test/coverband/adapters/base_test.rb +29 -30
  44. data/test/coverband/adapters/file_store_test.rb +15 -16
  45. data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
  46. data/test/coverband/adapters/redis_store_test.rb +26 -26
  47. data/test/coverband/at_exit_test.rb +2 -2
  48. data/test/coverband/collectors/coverage_test.rb +33 -47
  49. data/test/coverband/collectors/delta_test.rb +51 -23
  50. data/test/coverband/collectors/view_tracker_test.rb +35 -35
  51. data/test/coverband/configuration_test.rb +27 -53
  52. data/test/coverband/coverband_test.rb +11 -11
  53. data/test/coverband/integrations/background_middleware_test.rb +10 -10
  54. data/test/coverband/integrations/background_test.rb +3 -2
  55. data/test/coverband/integrations/rack_server_check_test.rb +7 -7
  56. data/test/coverband/integrations/report_middleware_test.rb +9 -9
  57. data/test/coverband/integrations/resque_worker_test.rb +9 -9
  58. data/test/coverband/integrations/test_resque_job.rb +1 -1
  59. data/test/coverband/reporters/base_test.rb +9 -9
  60. data/test/coverband/reporters/console_test.rb +6 -6
  61. data/test/coverband/reporters/html_test.rb +36 -48
  62. data/test/coverband/reporters/web_test.rb +16 -18
  63. data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
  64. data/test/coverband/utils/file_hasher_test.rb +6 -12
  65. data/test/coverband/utils/file_list_test.rb +13 -13
  66. data/test/coverband/utils/html_formatter_test.rb +9 -23
  67. data/test/coverband/utils/lines_classifier_test.rb +29 -29
  68. data/test/coverband/utils/relative_file_converter_test.rb +13 -13
  69. data/test/coverband/utils/result_test.rb +18 -18
  70. data/test/coverband/utils/results_test.rb +17 -17
  71. data/test/coverband/utils/source_file_line_test.rb +46 -46
  72. data/test/coverband/utils/source_file_test.rb +38 -88
  73. data/test/dog.rb +1 -1
  74. data/test/fake_app/basic_rack.rb +2 -2
  75. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  76. data/test/fixtures/app/models/user.rb +1 -1
  77. data/test/fixtures/sample.rb +1 -1
  78. data/test/fixtures/utf-8.rb +0 -2
  79. data/test/forked/rails_full_stack_test.rb +24 -27
  80. data/test/forked/rails_rake_full_stack_test.rb +7 -26
  81. data/test/integration/full_stack_test.rb +11 -22
  82. data/test/jruby_check.rb +2 -3
  83. data/test/rails4_dummy/Rakefile +1 -1
  84. data/test/rails4_dummy/config.ru +1 -1
  85. data/test/rails4_dummy/config/application.rb +4 -4
  86. data/test/rails4_dummy/config/boot.rb +2 -2
  87. data/test/rails4_dummy/config/coverband.rb +1 -1
  88. data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
  89. data/test/rails4_dummy/config/environment.rb +1 -1
  90. data/test/rails4_dummy/config/routes.rb +2 -2
  91. data/test/rails5_dummy/Rakefile +1 -1
  92. data/test/rails5_dummy/config.ru +1 -1
  93. data/test/rails5_dummy/config/application.rb +3 -3
  94. data/test/rails5_dummy/config/coverband.rb +8 -8
  95. data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
  96. data/test/rails5_dummy/config/environment.rb +1 -1
  97. data/test/rails5_dummy/config/routes.rb +2 -2
  98. data/test/rails6_dummy/Rakefile +1 -1
  99. data/test/rails6_dummy/config.ru +1 -1
  100. data/test/rails6_dummy/config/application.rb +4 -4
  101. data/test/rails6_dummy/config/boot.rb +2 -2
  102. data/test/rails6_dummy/config/coverband.rb +1 -1
  103. data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
  104. data/test/rails6_dummy/config/environment.rb +1 -1
  105. data/test/rails6_dummy/config/routes.rb +2 -2
  106. data/test/rails_test_helper.rb +11 -11
  107. data/test/test_helper.rb +41 -34
  108. data/test/unique_files.rb +10 -10
  109. data/views/layout.erb +2 -12
  110. metadata +5 -43
  111. data/.rubocop.yml +0 -84
  112. data/lib/coverband/integrations/bundler.rb +0 -8
  113. data/lib/coverband/utils/file_groups.rb +0 -53
  114. data/lib/coverband/utils/gem_list.rb +0 -31
  115. data/lib/coverband/utils/s3_report.rb +0 -105
  116. data/test/coverband/utils/file_groups_test.rb +0 -61
  117. data/test/coverband/utils/gem_list_test.rb +0 -48
  118. data/test/coverband/utils/s3_report_test.rb +0 -44
  119. data/views/gem_list.erb +0 -63
@@ -8,7 +8,7 @@ module Coverband
8
8
  ###
9
9
  class Base
10
10
  class << self
11
- DATA_KEY = 'data'
11
+ DATA_KEY = "data"
12
12
 
13
13
  def report(store, _options = {})
14
14
  all_roots = Coverband.configuration.all_root_paths
@@ -49,7 +49,7 @@ module Coverband
49
49
  protected
50
50
 
51
51
  def fix_file_names(report_hash, roots)
52
- Coverband.configuration.logger.debug "fixing root: #{roots.join(', ')}" if Coverband.configuration.verbose
52
+ Coverband.configuration.logger.debug "fixing root: #{roots.join(", ")}" if Coverband.configuration.verbose
53
53
 
54
54
  # normalize names across servers
55
55
  report_hash.each_with_object({}) do |(name, report), fixed_report|
@@ -57,12 +57,12 @@ module Coverband
57
57
  report.each_pair do |key, vals|
58
58
  filename = Coverband::Utils::AbsoluteFileConverter.convert(key)
59
59
  fixed_report[name][filename] = if fixed_report[name].key?(filename) && fixed_report[name][filename][DATA_KEY] && vals[DATA_KEY]
60
- merged_data = merge_arrays(fixed_report[name][filename][DATA_KEY], vals[DATA_KEY])
61
- vals[DATA_KEY] = merged_data
62
- vals
63
- else
64
- vals
65
- end
60
+ merged_data = merge_arrays(fixed_report[name][filename][DATA_KEY], vals[DATA_KEY])
61
+ vals[DATA_KEY] = merged_data
62
+ vals
63
+ else
64
+ vals
65
+ end
66
66
  end
67
67
  end
68
68
  end
@@ -75,8 +75,8 @@ module Coverband
75
75
 
76
76
  longest.each_with_index do |_line, index|
77
77
  merged[index] = if first[index] || second[index]
78
- (first[index].to_i + second[index].to_i)
79
- end
78
+ (first[index].to_i + second[index].to_i)
79
+ end
80
80
  end
81
81
 
82
82
  merged
@@ -12,7 +12,7 @@ module Coverband
12
12
  scov_style_report.each_pair do |file, usage|
13
13
  # TODO: In Coverband 5 deprecate none hash format
14
14
  if usage.is_a?(Hash)
15
- Coverband.configuration.logger.info "#{file}: #{usage['data']}"
15
+ Coverband.configuration.logger.info "#{file}: #{usage["data"]}"
16
16
  else
17
17
  Coverband.configuration.logger.info "#{file}: #{usage}"
18
18
  end
@@ -3,16 +3,15 @@
3
3
  module Coverband
4
4
  module Reporters
5
5
  class HTMLReport < Base
6
- attr_accessor :filtered_report_files, :open_report, :static, :notice,
7
- :base_path, :filename
6
+ attr_accessor :filtered_report_files, :open_report, :notice,
7
+ :base_path, :filename
8
8
 
9
9
  def initialize(store, options = {})
10
10
  coverband_reports = Coverband::Reporters::Base.report(store, options)
11
11
  self.open_report = options.fetch(:open_report) { true }
12
- self.static = options.fetch(:static) { true }
13
12
  # TODO: refactor notice out to top level of web only
14
13
  self.notice = options.fetch(:notice) { nil }
15
- self.base_path = options.fetch(:base_path) { nil }
14
+ self.base_path = options.fetch(:base_path) { "./" }
16
15
  self.filename = options.fetch(:filename) { nil }
17
16
 
18
17
  self.filtered_report_files = self.class.fix_reports(coverband_reports)
@@ -20,16 +19,12 @@ module Coverband
20
19
 
21
20
  def file_details
22
21
  Coverband::Utils::HTMLFormatter.new(filtered_report_files,
23
- base_path: base_path,
24
- notice: notice).format_source_file!(filename)
22
+ base_path: base_path,
23
+ notice: notice).format_source_file!(filename)
25
24
  end
26
25
 
27
26
  def report
28
- if static?
29
- report_static_site
30
- else
31
- report_dynamic_html
32
- end
27
+ report_dynamic_html
33
28
  end
34
29
 
35
30
  def report_data
@@ -38,31 +33,16 @@ module Coverband
38
33
 
39
34
  private
40
35
 
41
- def static?
42
- static
43
- end
44
-
45
- def report_static_site
46
- Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html!
47
- if open_report
48
- `open #{Coverband.configuration.root}/coverage/index.html`
49
- else
50
- Coverband.configuration.logger.info 'report is ready and viewable: open coverage/index.html'
51
- end
52
-
53
- Coverband::Utils::S3Report.instance.persist! if Coverband.configuration.s3_bucket
54
- end
55
-
56
36
  def report_dynamic_html
57
37
  Coverband::Utils::HTMLFormatter.new(filtered_report_files,
58
- base_path: base_path,
59
- notice: notice).format_dynamic_html!
38
+ base_path: base_path,
39
+ notice: notice).format_dynamic_html!
60
40
  end
61
41
 
62
42
  def report_dynamic_data
63
43
  Coverband::Utils::HTMLFormatter.new(filtered_report_files,
64
- base_path: base_path,
65
- notice: notice).format_dynamic_data!
44
+ base_path: base_path,
45
+ notice: notice).format_dynamic_data!
66
46
  end
67
47
  end
68
48
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  begin
4
- require 'rack'
4
+ require "rack"
5
5
  rescue LoadError
6
- puts 'error loading Coverband web reporter as Rack is not available'
6
+ puts "error loading Coverband web reporter as Rack is not available"
7
7
  end
8
8
 
9
9
  module Coverband
@@ -12,27 +12,31 @@ module Coverband
12
12
  attr_reader :request
13
13
 
14
14
  def initialize
15
- full_path = Gem::Specification.find_by_name('coverband').full_gem_path
15
+ init_web
16
+ end
17
+
18
+ def init_web
19
+ full_path = Gem::Specification.find_by_name("coverband").full_gem_path
16
20
  @static = Rack::Static.new(self,
17
- root: File.expand_path('public', full_path),
18
- urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/])
21
+ root: File.expand_path("public", full_path),
22
+ urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/])
19
23
  end
20
24
 
21
25
  def check_auth
22
26
  return true unless Coverband.configuration.password
23
27
 
24
- auth_header = request.get_header('HTTP_AUTHORIZATION')
28
+ auth_header = request.get_header("HTTP_AUTHORIZATION")
25
29
  return unless auth_header
26
30
 
27
- Coverband.configuration.password == Base64.decode64(auth_header.split[1]).split(':')[1]
31
+ Coverband.configuration.password == Base64.decode64(auth_header.split[1]).split(":")[1]
28
32
  end
29
33
 
30
34
  def call(env)
31
35
  @request = Rack::Request.new(env)
32
36
 
33
- return [401, { 'www-authenticate' => 'Basic realm=""' }, ['']] unless check_auth
37
+ return [401, {"www-authenticate" => 'Basic realm=""'}, [""]] unless check_auth
34
38
 
35
- request_path_info = (request.path_info == '') ? '/' : request.path_info
39
+ request_path_info = request.path_info == "" ? "/" : request.path_info
36
40
  if request.post?
37
41
  case request_path_info
38
42
  when %r{\/clear_view_tracking_file}
@@ -44,40 +48,40 @@ module Coverband
44
48
  when %r{\/clear}
45
49
  clear
46
50
  else
47
- [404, { 'Content-Type' => 'text/html' }, ['404 error!']]
51
+ [404, {"Content-Type" => "text/html"}, ["404 error!"]]
48
52
  end
49
53
  else
50
54
  case request_path_info
51
55
  when /.*\.(css|js|gif|png)/
52
56
  @static.call(env)
53
57
  when %r{\/settings}
54
- [200, { 'Content-Type' => 'text/html' }, [settings]]
58
+ [200, {"Content-Type" => "text/html"}, [settings]]
55
59
  when %r{\/view_tracker_data}
56
- [200, { 'Content-Type' => 'text/json' }, [view_tracker_data]]
60
+ [200, {"Content-Type" => "text/json"}, [view_tracker_data]]
57
61
  when %r{\/view_tracker}
58
- [200, { 'Content-Type' => 'text/html' }, [view_tracker]]
62
+ [200, {"Content-Type" => "text/html"}, [view_tracker]]
59
63
  when %r{\/enriched_debug_data}
60
- [200, { 'Content-Type' => 'text/json' }, [enriched_debug_data]]
64
+ [200, {"Content-Type" => "text/json"}, [enriched_debug_data]]
61
65
  when %r{\/debug_data}
62
- [200, { 'Content-Type' => 'text/json' }, [debug_data]]
66
+ [200, {"Content-Type" => "text/json"}, [debug_data]]
63
67
  when %r{\/load_file_details}
64
- [200, { 'Content-Type' => 'text/json' }, [load_file_details]]
68
+ [200, {"Content-Type" => "text/json"}, [load_file_details]]
65
69
  when %r{\/$}
66
- [200, { 'Content-Type' => 'text/html' }, [index]]
70
+ [200, {"Content-Type" => "text/html"}, [index]]
67
71
  else
68
- [404, { 'Content-Type' => 'text/html' }, ['404 error!']]
72
+ [404, {"Content-Type" => "text/html"}, ["404 error!"]]
69
73
  end
70
74
  end
71
75
  end
72
76
 
73
77
  def index
74
- notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>"
75
- notice = request.params['notice'] ? notice : ''
78
+ notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params["notice"])}<br/>"
79
+ notice = request.params["notice"] ? notice : ""
76
80
  Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
77
- static: false,
78
- base_path: base_path,
79
- notice: notice,
80
- open_report: false).report
81
+ static: false,
82
+ base_path: base_path,
83
+ notice: notice,
84
+ open_report: false).report
81
85
  end
82
86
 
83
87
  def settings
@@ -85,11 +89,11 @@ module Coverband
85
89
  end
86
90
 
87
91
  def view_tracker
88
- notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>"
89
- notice = request.params['notice'] ? notice : ''
92
+ notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params["notice"])}<br/>"
93
+ notice = request.params["notice"] ? notice : ""
90
94
  Coverband::Utils::HTMLFormatter.new(nil,
91
- notice: notice,
92
- base_path: base_path).format_view_tracker!
95
+ notice: notice,
96
+ base_path: base_path).format_view_tracker!
93
97
  end
94
98
 
95
99
  def view_tracker_data
@@ -102,62 +106,62 @@ module Coverband
102
106
 
103
107
  def enriched_debug_data
104
108
  Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
105
- static: false,
106
- base_path: base_path,
107
- notice: '',
108
- open_report: false).report_data
109
+ static: false,
110
+ base_path: base_path,
111
+ notice: "",
112
+ open_report: false).report_data
109
113
  end
110
114
 
111
115
  def load_file_details
112
- filename = request.params['filename']
116
+ filename = request.params["filename"]
113
117
  Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
114
- filename: filename,
115
- base_path: base_path,
116
- open_report: false).file_details
118
+ filename: filename,
119
+ base_path: base_path,
120
+ open_report: false).file_details
117
121
  end
118
122
 
119
123
  def clear
120
124
  if Coverband.configuration.web_enable_clear
121
125
  Coverband.configuration.store.clear!
122
- notice = 'coverband coverage cleared'
126
+ notice = "coverband coverage cleared"
123
127
  else
124
- notice = 'web_enable_clear isnt enabled in your configuration'
128
+ notice = "web_enable_clear isnt enabled in your configuration"
125
129
  end
126
- [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
130
+ [301, {"Location" => "#{base_path}?notice=#{notice}"}, []]
127
131
  end
128
132
 
129
133
  def clear_file
130
134
  if Coverband.configuration.web_enable_clear
131
- filename = request.params['filename']
135
+ filename = request.params["filename"]
132
136
  Coverband.configuration.store.clear_file!(filename)
133
137
  notice = "coverage for file #{filename} cleared"
134
138
  else
135
- notice = 'web_enable_clear isnt enabled in your configuration'
139
+ notice = "web_enable_clear isnt enabled in your configuration"
136
140
  end
137
- [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
141
+ [301, {"Location" => "#{base_path}?notice=#{notice}"}, []]
138
142
  end
139
143
 
140
144
  def clear_view_tracking
141
145
  if Coverband.configuration.web_enable_clear
142
146
  tracker = Coverband::Collectors::ViewTracker.new(store: Coverband.configuration.store)
143
147
  tracker.reset_recordings
144
- notice = 'view tracking reset'
148
+ notice = "view tracking reset"
145
149
  else
146
- notice = 'web_enable_clear isnt enabled in your configuration'
150
+ notice = "web_enable_clear isnt enabled in your configuration"
147
151
  end
148
- [301, { 'Location' => "#{base_path}/view_tracker?notice=#{notice}" }, []]
152
+ [301, {"Location" => "#{base_path}/view_tracker?notice=#{notice}"}, []]
149
153
  end
150
154
 
151
155
  def clear_view_tracking_file
152
156
  if Coverband.configuration.web_enable_clear
153
157
  tracker = Coverband::Collectors::ViewTracker.new(store: Coverband.configuration.store)
154
- filename = request.params['filename']
158
+ filename = request.params["filename"]
155
159
  tracker.clear_file!(filename)
156
160
  notice = "coverage for file #{filename} cleared"
157
161
  else
158
- notice = 'web_enable_clear isnt enabled in your configuration'
162
+ notice = "web_enable_clear isnt enabled in your configuration"
159
163
  end
160
- [301, { 'Location' => "#{base_path}/view_tracker?notice=#{notice}" }, []]
164
+ [301, {"Location" => "#{base_path}/view_tracker?notice=#{notice}"}, []]
161
165
  end
162
166
 
163
167
  private
@@ -167,8 +171,11 @@ module Coverband
167
171
  # mount Coverband::Web, at: '/coverage'
168
172
  # "/coverage/collect_coverage?" become:
169
173
  # /coverage/
174
+ # NOTE: DO NOT let standardrb `autofix` this to regex match
175
+ # %r{\/.*\/}.match?(request.path) ? request.path.match("\/.*\/")[0] : "/"
176
+ # ^^ the above is NOT valid Ruby 2.3/2.4 even though rubocop / standard think it is
170
177
  def base_path
171
- request.path =~ %r{\/.*\/} ? request.path.match("\/.*\/")[0] : '/'
178
+ request.path =~ %r{\/.*\/} ? request.path.match("\/.*\/")[0] : "/"
172
179
  end
173
180
  end
174
181
  end
@@ -25,9 +25,9 @@ module Coverband
25
25
  relative_filename = relative_path
26
26
  local_filename = relative_filename
27
27
  @roots.each do |root|
28
- relative_filename = relative_filename.sub(/^#{root}/, './')
28
+ relative_filename = relative_filename.sub(/^#{root}/, "./")
29
29
  # once we have a relative path break out of the loop
30
- break if relative_filename.start_with? './'
30
+ break if relative_filename.start_with? "./"
31
31
  end
32
32
  # the filename for our reports is expected to be a full path.
33
33
  # roots.last should be roots << current_root}/
@@ -36,10 +36,10 @@ module Coverband
36
36
  # above only works for app files
37
37
  # we need to rethink some of this logic
38
38
  # gems aren't at project root and can have multiple locations
39
- local_root = @roots.find do |root|
40
- File.exist?(relative_filename.gsub('./', root))
41
- end
42
- local_root ? relative_filename.gsub('./', local_root) : local_filename
39
+ local_root = @roots.find { |root|
40
+ File.exist?(relative_filename.gsub("./", root))
41
+ }
42
+ local_root ? relative_filename.gsub("./", local_root) : local_filename
43
43
  end
44
44
  end
45
45
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
- require 'cgi'
5
- require 'fileutils'
6
- require 'digest/sha1'
7
- require 'time'
3
+ require "erb"
4
+ require "cgi"
5
+ require "fileutils"
6
+ require "digest/sha1"
7
+ require "time"
8
8
 
9
9
  ####
10
10
  # Thanks for all the help SimpleCov https://github.com/colszowka/simplecov-html
@@ -17,14 +17,10 @@ module Coverband
17
17
 
18
18
  def initialize(report, options = {})
19
19
  @notice = options.fetch(:notice) { nil }
20
- @base_path = options.fetch(:base_path) { nil }
20
+ @base_path = options.fetch(:base_path) { "./" }
21
21
  @coverage_result = Coverband::Utils::Results.new(report) if report
22
22
  end
23
23
 
24
- def format_static_html!
25
- format(@coverage_result)
26
- end
27
-
28
24
  def format_dynamic_html!
29
25
  format_html(@coverage_result)
30
26
  end
@@ -47,41 +43,41 @@ module Coverband
47
43
  if source_file
48
44
  formatted_source_file(@coverage_result, source_file)
49
45
  else
50
- 'File No Longer Available'
46
+ "File No Longer Available"
51
47
  end
52
48
  end
53
49
 
54
50
  private
55
51
 
56
52
  def format_settings
57
- template('settings').result(binding)
53
+ template("settings").result(binding)
58
54
  end
59
55
 
60
56
  def format_view_tracker
61
- template('view_tracker').result(binding)
57
+ template("view_tracker").result(binding)
62
58
  end
63
59
 
64
60
  def format(result)
65
- Dir[File.join(File.dirname(__FILE__), '../../../public/*')].each do |path|
61
+ Dir[File.join(File.dirname(__FILE__), "../../../public/*")].each do |path|
66
62
  FileUtils.cp_r(path, asset_output_path)
67
63
  end
68
64
 
69
- File.open(File.join(output_path, 'index.html'), 'wb') do |file|
70
- file.puts template('layout').result(binding)
65
+ File.open(File.join(output_path, "index.html"), "wb") do |file|
66
+ file.puts template("layout").result(binding)
71
67
  end
72
68
  end
73
69
 
74
70
  def format_html(result)
75
- template('layout').result(binding)
71
+ template("layout").result(binding)
76
72
  end
77
73
 
78
74
  def format_data(result)
79
- template('data').result(binding)
75
+ template("data").result(binding)
80
76
  end
81
77
 
82
78
  # Returns the an erb instance for the template of given name
83
79
  def template(name)
84
- ERB.new(File.read(File.join(File.dirname(__FILE__), '../../../views/', "#{name}.erb")))
80
+ ERB.new(File.read(File.join(File.dirname(__FILE__), "../../../views/", "#{name}.erb")))
85
81
  end
86
82
 
87
83
  def output_path
@@ -97,90 +93,70 @@ module Coverband
97
93
  end
98
94
 
99
95
  def served_html?
100
- !static_html?
101
- end
102
-
103
- def static_html?
104
- base_path.nil?
96
+ true
105
97
  end
106
98
 
107
99
  def assets_path(name)
108
- if static_html?
109
- File.join(name)
110
- else
111
- File.join(base_path, name)
112
- end
100
+ File.join(base_path, name)
113
101
  end
114
102
 
115
103
  def button(url, title, opts = {})
116
104
  delete = opts.fetch(:delete) { false }
117
- button_css = delete ? 'coveraband-button del' : 'coveraband-button'
105
+ button_css = delete ? "coveraband-button del" : "coveraband-button"
118
106
  button = "<form action='#{url}' class='coverband-admin-form' method='post'>"
119
107
  button += "<button class='#{button_css}' type='submit'>#{title}</button>"
120
- button + '</form>'
108
+ button + "</form>"
121
109
  end
122
110
 
123
111
  def display_nav(nav_options = {})
124
- template('nav').result(binding)
112
+ template("nav").result(binding)
125
113
  end
126
114
 
127
115
  # Returns the html for the given source_file
128
116
  def formatted_source_file(result, source_file)
129
- template('source_file').result(binding)
117
+ template("source_file").result(binding)
130
118
  rescue Encoding::CompatibilityError => e
131
119
  puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}."
132
120
  end
133
121
 
134
122
  # Returns the html to ajax load a given source_file
135
123
  def formatted_source_file_loader(result, source_file)
136
- template('source_file_loader').result(binding)
124
+ template("source_file_loader").result(binding)
137
125
  rescue Encoding::CompatibilityError => e
138
126
  puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}."
139
127
  end
140
128
 
141
129
  # Returns a table containing the given source files
142
130
  def formatted_file_list(title, result, source_files, options = {})
143
- title_id = title.gsub(/^[^a-zA-Z]+/, '').gsub(/[^a-zA-Z0-9\-\_]/, '')
131
+ title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
144
132
  # Silence a warning by using the following variable to assign to itself:
145
133
  # "warning: possibly useless use of a variable in void context"
146
134
  # The variable is used by ERB via binding.
147
135
  title_id = title_id
148
136
  options = options
149
137
 
150
- if title == 'Gems'
151
- template('gem_list').result(binding)
152
- else
153
- template('file_list').result(binding)
154
- end
155
- end
156
-
157
- def view_gems?
158
- Coverband.configuration.track_gems
159
- end
160
-
161
- def gem_details?
162
- Coverband.configuration.gem_details
138
+ template("file_list").result(binding)
163
139
  end
164
140
 
165
141
  def coverage_css_class(covered_percent)
166
142
  if covered_percent.nil?
167
- ''
143
+ ""
168
144
  elsif covered_percent > 90
169
- 'green'
145
+ "green"
170
146
  elsif covered_percent > 80
171
- 'yellow'
147
+ "yellow"
172
148
  else
173
- 'red'
149
+ "red"
174
150
  end
175
151
  end
176
152
 
177
153
  def strength_css_class(covered_strength)
178
154
  if covered_strength > 1
179
- 'green'
155
+ "green"
180
156
  elsif covered_strength == 1
181
- 'yellow'
157
+ "yellow"
182
158
  else
183
- 'red'
159
+ "red"
184
160
  end
185
161
  end
186
162
 
@@ -193,7 +169,7 @@ module Coverband
193
169
  if time
194
170
  "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
195
171
  else
196
- 'Not Available'
172
+ "Not Available"
197
173
  end
198
174
  end
199
175
 
@@ -201,11 +177,6 @@ module Coverband
201
177
  source_file.short_name
202
178
  end
203
179
 
204
- def link_to_gem_list(gem_name)
205
- gem_id = gem_name.gsub(/^[^a-zA-Z]+/, '').gsub(/[^a-zA-Z0-9\-\_]/, '')
206
- %(<a href="##{gem_id}" class="gem-link" title="#{gem_name}">#{gem_name}</a>)
207
- end
208
-
209
180
  def link_to_source_file(source_file)
210
181
  %(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}">#{shortened_filename source_file}</a>)
211
182
  end