Class: FluentLoggerStatistics::Middleware
- Inherits:
-
Object
- Object
- FluentLoggerStatistics::Middleware
- Defined in:
- lib/fluent_logger_statistics/middleware.rb
Constant Summary collapse
- ACCEPT_METHODS =
['GET'].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, endpoint, loggers) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, endpoint, loggers) ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 8 9 10 11 |
# File 'lib/fluent_logger_statistics/middleware.rb', line 5 def initialize(app, endpoint, loggers) @app = app @fluent_apps = loggers.map{|resource, logger| path = [ endpoint.chomp('/'), resource ].join('/') [ path, App.new(logger) ] }.to_h end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fluent_logger_statistics/middleware.rb', line 15 def call(env) path = env['PATH_INFO'].chomp('/') if @fluent_apps[path] && ACCEPT_METHODS.include?(env['REQUEST_METHOD']) @fluent_apps[path].call(env) else @app.call(env) end end |