lib/coverband/reporters/web.rb in coverband-2.0.3 vs lib/coverband/reporters/web.rb in coverband-3.0.0.alpha
- old
+ new
@@ -7,75 +7,78 @@
# TODO: move to reports and drop need for S3 allow reading from adapters?
class Web
attr_reader :request
def initialize
+ full_path = Gem::Specification.find_by_name('simplecov-html').full_gem_path
@static = Rack::Static.new(self,
- root: File.expand_path('public', Gem::Specification.find_by_name('simplecov-html').full_gem_path),
- urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/]
- )
+ root: File.expand_path('public', full_path),
+ urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/])
end
def call(env)
@request = Rack::Request.new(env)
if request.post?
case request.path_info
- when /\/collect_update_and_view/
+ when %r{\/collect_update_and_view}
collect_update_and_view
- when /\/clear/
+ when %r{\/clear}
clear
- when /\/update_report/
+ when %r{\/update_report}
update_report
- when /\/collect_coverage/
+ when %r{\/collect_coverage}
collect_coverage
- when /\/reload_files/
+ when %r{\/reload_files}
reload_files
else
- [404, {'Content-Type' => 'text/html'}, ['404 error!']]
+ [404, { 'Content-Type' => 'text/html' }, ['404 error!']]
end
else
case request.path_info
when /.*\.(css|js|gif|png)/
@static.call(env)
- when /\/show/
- [200, {'Content-Type' => 'text/html'}, [show]]
- when /\//
- [200, {'Content-Type' => 'text/html'}, [index]]
+ when %r{\/show}
+ [200, { 'Content-Type' => 'text/html' }, [show]]
+ when %r{\/}
+ [200, { 'Content-Type' => 'text/html' }, [index]]
else
- [404, {'Content-Type' => 'text/html'}, ['404 error!']]
+ [404, { 'Content-Type' => 'text/html' }, ['404 error!']]
end
end
end
- # todo move to file or template
+ # TODO: move to file or template
def index
- html = "<html>"
- html += "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>" if request.params['notice']
- html += "<ul>"
- html += "<li><a href='#{base_path}'>Coverband Web Admin Index</a></li>"
- html += "<li>#{button("#{base_path}collect_update_and_view",'collect data, update report, & view')}</li>"
- html += "<li><a href='#{base_path}show'>view coverage report</a></li>"
- html += "<li>#{button("#{base_path}collect_coverage",'update coverage data (collect coverage)')}</li>"
- html += "<li>#{button("#{base_path}update_report",'update coverage report (rebuild report)')}</li>"
- html += "<li>#{button("#{base_path}clear",'clear coverage report')}</li>"
- html += "<li>#{button("#{base_path}reload_files",'reload Coverband files')}</li>"
- html += "</ul>"
- html += "<br/>"
- html += "version: #{Coverband::VERSION}<br/>"
- html += "<a href='https://github.com/danmayer/coverband'>Coverband</a>"
- html += "</html>"
- html
+ notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>"
+ notice = request.params['notice'] ? notice : ''
+ %(
+<html>
+ #{notice}
+ <ul>
+ <li><a href='#{base_path}'>Coverband Web Admin Index</a></li>
+ <li>#{button("#{base_path}collect_update_and_view", 'collect data, update report, & view')}</li>
+ <li><a href='#{base_path}show'>view coverage report</a></li>
+ <li>#{button("#{base_path}collect_coverage", 'update coverage data (collect coverage)')}</li>
+ <li>#{button("#{base_path}update_report", 'update coverage report (rebuild report)')}</li>
+ <li>#{button("#{base_path}clear", 'clear coverage report')}</li>
+ <li>#{button("#{base_path}reload_files", 'reload Coverband files')}</li>
+ </ul>
+ <br/>
+ version: #{Coverband::VERSION}<br/>
+ <a href='https://github.com/danmayer/coverband'>Coverband</a>
+</html>
+)
end
def show
html = s3.get_object(bucket: Coverband.configuration.s3_bucket, key: 'coverband/index.html').body.read
- # hack the static HTML assets to link to the path where this was mounted
+ # HACK: the static HTML assets to link to the path where this was mounted
html = html.gsub("src='", "src='#{base_path}")
html = html.gsub("href='", "href='#{base_path}")
- html = html.gsub("loading.gif", "#{base_path}loading.gif")
- html = html.gsub("/images/", "#{base_path}images/")
+ html = html.gsub('loading.gif', "#{base_path}loading.gif")
+ html = html.gsub('/images/', "#{base_path}images/")
html
end
def collect_update_and_view
collect_coverage
@@ -88,10 +91,10 @@
notice = 'coverband coverage updated'
[301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
end
def collect_coverage
- Coverband::Collectors::Base.instance.report_coverage
+ Coverband::Collectors::Coverage.instance.report_coverage
notice = 'coverband coverage collected'
[301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
end
def clear