Class: Pilfer::Middleware
- Inherits:
-
Object
- Object
- Pilfer::Middleware
- Defined in:
- lib/pilfer/middleware.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#file_matcher ⇒ Object
Returns the value of attribute file_matcher.
-
#profile_guard ⇒ Object
Returns the value of attribute profile_guard.
-
#profiler ⇒ Object
Returns the value of attribute profiler.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #default_profiler ⇒ Object
-
#initialize(app, options = {}, &profile_guard) ⇒ Middleware
constructor
A new instance of Middleware.
- #request_description(env) ⇒ Object
- #run_profiler(description, &downstream) ⇒ Object
Constructor Details
#initialize(app, options = {}, &profile_guard) ⇒ Middleware
Returns a new instance of Middleware.
8 9 10 11 12 13 |
# File 'lib/pilfer/middleware.rb', line 8 def initialize(app, = {}, &profile_guard) @app = app @profiler = [:profiler] || default_profiler @file_matcher = [:file_matcher] @profile_guard = profile_guard || proc { true } end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
6 7 8 |
# File 'lib/pilfer/middleware.rb', line 6 def app @app end |
#file_matcher ⇒ Object
Returns the value of attribute file_matcher.
6 7 8 |
# File 'lib/pilfer/middleware.rb', line 6 def file_matcher @file_matcher end |
#profile_guard ⇒ Object
Returns the value of attribute profile_guard.
6 7 8 |
# File 'lib/pilfer/middleware.rb', line 6 def profile_guard @profile_guard end |
#profiler ⇒ Object
Returns the value of attribute profiler.
6 7 8 |
# File 'lib/pilfer/middleware.rb', line 6 def profiler @profiler end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 |
# 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 ⇒ Object
32 33 34 35 |
# File 'lib/pilfer/middleware.rb', line 32 def default_profiler reporter = Pilfer::Logger.new($stdout) Pilfer::Profiler.new(reporter) end |
#request_description(env) ⇒ Object
37 38 39 |
# File 'lib/pilfer/middleware.rb', line 37 def request_description(env) "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}" end |
#run_profiler(description, &downstream) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 |