Sha256: 8437e9012ea1db5c1902ab60d3890f2f0b92d12cfc71bd62d41f846fab85a29d

Contents?: true

Size: 770 Bytes

Versions: 15

Compression:

Stored size: 770 Bytes

Contents

require 'routemaster/dirty/filter'

module Routemaster
  module Middleware
    # Filters event payloads passed in the environment (in
    # `env['routemaster.payload']`), is any.
    #
    # Will use `Routemaster::Dirty::Filter` by default.
    class Filter
      # @param filter [Routemaster::Dirty::Filter] an event filter (optional;
      # will be created using the `redis` and `expiry` options if not provided)
      def initialize(app, filter:nil)
        @app    = app
        @filter = filter || Routemaster::Dirty::Filter.new
      end

      def call(env)
        payload = env['routemaster.payload']
        if payload && payload.any?
          env['routemaster.payload'] = @filter.run(payload)
        end
        @app.call(env) 
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
routemaster-drain-2.4.4 lib/routemaster/middleware/filter.rb
routemaster-drain-2.4.3 lib/routemaster/middleware/filter.rb
routemaster-drain-2.4.2 lib/routemaster/middleware/filter.rb
routemaster-drain-2.4.1 lib/routemaster/middleware/filter.rb
routemaster-drain-2.4.0 lib/routemaster/middleware/filter.rb
routemaster-drain-2.3.0 lib/routemaster/middleware/filter.rb
routemaster-drain-2.2.2 lib/routemaster/middleware/filter.rb
routemaster-drain-2.0.0 lib/routemaster/middleware/filter.rb
routemaster-drain-1.1.0 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.5 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.4 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.3 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.2 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.1 lib/routemaster/middleware/filter.rb
routemaster-drain-1.0.0 lib/routemaster/middleware/filter.rb