lib/attractor/reporters/sinatra_reporter.rb in attractor-2.0.5 vs lib/attractor/reporters/sinatra_reporter.rb in attractor-2.1.0
- old
+ new
@@ -1,59 +1,59 @@
# frozen_string_literal: true
-require 'rack/livereload'
-require 'rack'
-require 'sinatra/base'
+require "rack/livereload"
+require "rack"
+require "sinatra/base"
module Attractor
# skeleton sinatra app
class AttractorApp < Sinatra::Base
def initialize(reporter)
super
@reporter = reporter
end
enable :static
- set :public_folder, File.expand_path('../../../app/assets', __dir__)
+ set :public_folder, File.expand_path("../../../app/assets", __dir__)
set :show_exceptions, :after_handler
- get '/' do
+ get "/" do
@types = @reporter.types
- erb File.read(File.expand_path('../../../app/views/index.html.erb', __dir__))
+ erb File.read(File.expand_path("../../../app/views/index.html.erb", __dir__))
end
- get '/file_prefix' do
- { file_prefix: @reporter.file_prefix }.to_json
+ get "/file_prefix" do
+ {file_prefix: @reporter.file_prefix}.to_json
end
- get '/values' do
- type = params[:type] || 'rb'
+ get "/values" do
+ type = params[:type] || "rb"
@reporter.values(type: type).to_json
end
- get '/suggestions' do
+ get "/suggestions" do
threshold = params[:t] || 95
- type = params[:type] || 'rb'
+ type = params[:type] || "rb"
@reporter.suggestions(quantile: threshold, type: type).to_json
end
error NoMethodError do
- { error: env['sinatra.error'].message }.to_json
+ {error: env["sinatra.error"].message}.to_json
end
end
# serving the HTML locally
class SinatraReporter < BaseReporter
def report
super
app = AttractorApp.new(self)
- puts 'Serving attractor at http://localhost:7890'
+ puts "Serving attractor at http://localhost:7890"
if @open_browser
- Launchy.open('http://localhost:7890') if @open_browser
+ Launchy.open("http://localhost:7890") if @open_browser
puts "Opening browser window..."
end
Rack::Handler::WEBrick.run app, Port: 7890
end
@@ -61,12 +61,12 @@
def watch
@suggestions = @suggester.suggest
app = AttractorApp.new(self)
- puts 'Serving attractor at http://localhost:7890'
+ puts "Serving attractor at http://localhost:7890"
if @open_browser
- Launchy.open('http://localhost:7890')
+ Launchy.open("http://localhost:7890")
puts "Opening browser window..."
end
Rack::Handler::WEBrick.run Rack::LiveReload.new(app), Port: 7890
end