class Pilfer::Middleware
Attributes
app[RW]
file_matcher[RW]
profile_guard[RW]
profiler[RW]
Public Class Methods
new(app, options = {}, &profile_guard)
click to toggle source
# File lib/pilfer/middleware.rb, line 8 def initialize(app, options = {}, &profile_guard) @app = app @profiler = options[:profiler] || default_profiler @file_matcher = options[:file_matcher] @profile_guard = profile_guard || proc { true } end
Public Instance Methods
call(env)
click to toggle source
# File lib/pilfer/middleware.rb, line 15 def call(env) if profile_guard.call(env) run_profiler(request_description(env)) { app.call(env) } else app.call(env) end end
default_profiler()
click to toggle source
# File lib/pilfer/middleware.rb, line 32 def default_profiler reporter = Pilfer::Logger.new($stdout) Pilfer::Profiler.new(reporter) end
request_description(env)
click to toggle source
# File lib/pilfer/middleware.rb, line 37 def request_description(env) "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}" end
run_profiler(description, &downstream)
click to toggle source
# File lib/pilfer/middleware.rb, line 23 def run_profiler(description, &downstream) if file_matcher profiler.profile_files_matching(file_matcher, description, :submit => :async, &downstream) else profiler.profile(description, :submit => :async, &downstream) end end