Class: Routemaster::Middleware::Dirty
- Inherits:
-
Object
- Object
- Routemaster::Middleware::Dirty
- Defined in:
- lib/routemaster/middleware/dirty.rb
Overview
If an event payload was place in the environment
(env['routemaster.payload']
) by a previous middleware,
mark each corresponding entity as dirty.
All events are passed through.
The dirty map is passed as :map
to the constructor and must respond to
#mark
(like Routemaster::Dirty::Map
).
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Dirty
constructor
A new instance of Dirty.
Constructor Details
#initialize(app, options = {}) ⇒ Dirty
Returns a new instance of Dirty.
14 15 16 17 |
# File 'lib/routemaster/middleware/dirty.rb', line 14 def initialize(app, = {}) @app = app @map = .fetch(:dirty_map) { Routemaster::Dirty::Map.new } end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/routemaster/middleware/dirty.rb', line 19 def call(env) env['routemaster.dirty'] = dirty = [] env.fetch('routemaster.payload', []).each do |event| next if event['type'] == 'noop' next unless @map.mark(event['url']) dirty << event['url'] end @app.call(env) end |