lib/stackprof-webnav/server.rb in stackprof-webnav-0.0.3 vs lib/stackprof-webnav/server.rb in stackprof-webnav-0.0.4
- old
+ new
@@ -1,46 +1,42 @@
require 'nyny'
require 'haml'
require "stackprof"
-require 'sprockets/nyny'
require 'net/http'
require_relative 'presenter'
module StackProf
module Webnav
class Server < NYNY::App
- register Sprockets::NYNY
- config.assets.paths << File.join(__dir__, 'css')
-
class << self
- attr_accessor :cmd_options, :report_dump_path, :report_dump_uri, :report_dump_listing
+ attr_accessor :cmd_options, :report_dump_path, :report_dump_uri, :report_dump_listing
def presenter regenerate=false
return @presenter unless regenerate || @presenter.nil?
process_options
if self.report_dump_path || self.report_dump_uri
report_contents = if report_dump_path.nil?
- Net::HTTP.get(URI.parse(report_dump_uri))
- else
+ Net::HTTP.get(URI.parse(report_dump_uri))
+ else
File.open(report_dump_path).read
end
report = StackProf::Report.new(Marshal.load(report_contents))
end
@presenter = Presenter.new(report)
end
private
def process_options
- if cmd_options[:filepath]
- self.report_dump_path = cmd_options[:filepath]
- elsif cmd_options[:uri]
- self.report_dump_uri = cmd_options[:uri]
+ if cmd_options[:filepath]
+ self.report_dump_path = cmd_options[:filepath]
+ elsif cmd_options[:uri]
+ self.report_dump_uri = cmd_options[:uri]
elsif cmd_options[:bucket]
self.report_dump_listing = cmd_options[:bucket]
- end
+ end
end
-
+
end
helpers do
def template_path name
File.join(__dir__, name)
@@ -60,20 +56,20 @@
end
def file_url path
"/file?path=#{URI.escape(path)}"
end
-
+
def overview_url path
"/overview?path=#{URI.escape(path)}"
end
end
get '/' do
presenter
if Server.report_dump_listing
- redirect_to '/listing'
+ redirect_to '/listing'
else
redirect_to '/overview'
end
end
@@ -89,12 +85,12 @@
end
get '/listing' do
@file = Server.report_dump_listing
@action = "listing"
- @dumps = presenter.listing_dumps
+ @dumps = presenter.listing_dumps
render_with_layout :listing
- end
+ end
get '/method' do
@action = params[:name]
@frames = presenter.method_info(params[:name])
render_with_layout :method