make filters pluggable

This commit is contained in:
Sven Fuchs 2012-10-03 17:20:36 +02:00
parent 7b47863014
commit 5166e65e84

View File

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