Sha256: 7221dafb6f40e2cf1b1102eac00e4caec3f6ca8617e2d70dc3d197a787989ea2

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

require 'routemaster/dirty/map'

module Routemaster
  module Middleware
    # 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`).
    class Dirty
      def initialize(app, dirty_map: nil, **_)
        @app = app
        @map = dirty_map || Routemaster::Dirty::Map.new
      end

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
routemaster-drain-2.5.0 lib/routemaster/middleware/dirty.rb