lib/attractor/reporters/sinatra_reporter.rb in attractor-0.6.1 vs lib/attractor/reporters/sinatra_reporter.rb in attractor-1.0.0
- old
+ new
@@ -13,27 +13,33 @@
@reporter = reporter
end
enable :static
set :public_folder, File.expand_path('../../../app/assets', __dir__)
+ set :show_exceptions, :after_handler
get '/' do
erb File.read(File.expand_path('../../../app/views/index.html.erb', __dir__))
end
get '/file_prefix' do
{ file_prefix: @reporter.file_prefix }.to_json
end
get '/values' do
- @reporter.values.to_json
+ type = params[:type] || 'rb'
+ @reporter.values(type: type).to_json
end
get '/suggestions' do
threshold = params[:t] || 95
@reporter.suggestions(threshold).to_json
end
+
+ error NoMethodError do
+ { error: env['sinatra.error'].message }.to_json
+ end
end
# serving the HTML locally
class SinatraReporter < BaseReporter
def report
@@ -54,8 +60,13 @@
puts 'Serving attractor at http://localhost:7890'
Launchy.open('http://localhost:7890')
Rack::Handler::WEBrick.run Rack::LiveReload.new(app), Port: 7890
+ end
+
+ def values(type: 'rb')
+ @values = @calculators[type].calculate
+ @values
end
end
end