# frozen_string_literal: true
require 'rack'
module Coverband
module Reporters
# 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', full_path),
urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/])
end
def call(env)
@request = Rack::Request.new(env)
if request.post?
case request.path_info
when %r{\/collect_update_and_view}
collect_update_and_view
when %r{\/clear}
clear
when %r{\/update_report}
update_report
when %r{\/collect_coverage}
collect_coverage
when %r{\/reload_files}
reload_files
else
[404, { 'Content-Type' => 'text/html' }, ['404 error!']]
end
else
case request.path_info
when /.*\.(css|js|gif|png)/
@static.call(env)
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!']]
end
end
end
# TODO: move to file or template
def index
notice = "Notice: #{Rack::Utils.escape_html(request.params['notice'])}
"
notice = request.params['notice'] ? notice : ''
%(
#{notice}