Class: Utopia::Middleware::Filter
- Inherits:
-
Object
- Object
- Utopia::Middleware::Filter
- Defined in:
- lib/utopia/middleware/filter.rb
Overview
This class filters a incoming request and only executes a given block if it matches the given filter path.
Instance Method Summary collapse
- #applicable(request) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, filter, &block) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(app, filter, &block) ⇒ Filter
Returns a new instance of Filter.
28 29 30 31 32 33 34 |
# File 'lib/utopia/middleware/filter.rb', line 28 def initialize(app, filter, &block) @app = app @filter = filter branch = Rack::Builder.new(&block) branch.run(@app) @process = branch.to_app end |
Instance Method Details
#applicable(request) ⇒ Object
36 37 38 |
# File 'lib/utopia/middleware/filter.rb', line 36 def applicable(request) return request.path.index(@filter) != nil end |
#call(env) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/utopia/middleware/filter.rb', line 40 def call(env) request = Rack::Request.new(env) if applicable(request) @process.call(env) else @app.call(env) end end |