From 5166e65e84437900f4423bba71c3c6113fab0eef Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 3 Oct 2012 17:20:36 +0200 Subject: [PATCH] make filters pluggable --- lib/travis/web/app/filter.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/travis/web/app/filter.rb b/lib/travis/web/app/filter.rb index 4fbc57ab..18eb2751 100644 --- a/lib/travis/web/app/filter.rb +++ b/lib/travis/web/app/filter.rb @@ -3,12 +3,11 @@ class Travis::Web::App autoload :Endpoint, 'travis/web/app/filter/endpoint' autoload :Assets, 'travis/web/app/filter/assets' - attr_reader :app, :config, :filters + attr_reader :app, :config def initialize(app, config) @app = app @config = config - @filters = [Endpoint.new(config), Assets.new(config)] end def call(env) @@ -27,6 +26,10 @@ class Travis::Web::App [headers, filtered] end + def filters + @filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) } + end + def content_type?(headers, type) headers.any? { |key, value| key.downcase == 'content-type' and value.start_with?(type) } end