lib/coverband/s3_web.rb in coverband-2.0.0 vs lib/coverband/s3_web.rb in coverband-2.0.1.alpha

- old
+ new

@@ -5,21 +5,58 @@ module Coverband class S3Web < Sinatra::Base set :public_folder, proc(){ File.expand_path('public', Gem::Specification.find_by_name('simplecov-html').full_gem_path) } get '/' do - s3.get_object(bucket: Coverband.configuration.s3_bucket, key: 'coverband/index.html').body.read + html = s3.get_object(bucket: Coverband.configuration.s3_bucket, key: 'coverband/index.html').body.read + # hack the static HTML assets to account for where this was mounted + html = html.gsub("src='", "src='#{request.path}") + html = html.gsub("href='", "href='#{request.path}") + html = html.gsub("loading.gif", "#{request.path}loading.gif") + html = html.gsub("/images/", "#{request.path}/images/") + html end + post '/update_report' do + Coverband::Reporters::SimpleCovReport.report(Coverband.configuration.store, open_report: false) + notice = "coverband coverage updated" + redirect "/?notice=#{notice}", 301 + end + + post '/clear' do + Coverband.configuration.store.clear! + notice = "coverband coverage cleared" + redirect "/?notice=#{notice}", 301 + end + + post '/reload_files' do + if Coverband.configuration.safe_reload_files + Coverband.configuration.safe_reload_files.each do |safe_file| + load safe_file + end + end + Coverband.configure + notice = "coverband files reloaded" + redirect "/?notice=#{notice}", 301 + end + private def s3 begin require 'aws-sdk' rescue StandardError Coverband.configuration.logger.error "coverband requires 'aws-sdk' in order use S3ReportWriter." return end - @s3 ||= Aws::S3::Client.new + @s3 ||= begin + client_options = { + region: Coverband.configuration.s3_region, + access_key_id: Coverband.configuration.s3_access_key_id, + secret_access_key: Coverband.configuration.s3_secret_access_key + } + client_options = {} if client_options.values.any?(&:nil?) + Aws::S3::Client.new(client_options) + end end end end