Sha256: d7977791639bc661aa1f4388707e2c7a4d3b08fd87e75a2c9507287672e950eb

Contents?: true

Size: 797 Bytes

Versions: 18

Compression:

Stored size: 797 Bytes

Contents

#	This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3.
#	Copyright 2010 Samuel Williams. All rights reserved.
#	See <utopia.rb> for licensing details.
require 'utopia/middleware'

module Utopia
	module Middleware

		# This class filters a incoming request and only executes a given block if it matches the given filter path.
		class Filter
			def initialize(app, filter, &block)
				@app = app
				@filter = filter
				branch = Rack::Builder.new(&block)
				branch.run(@app)
				@process = branch.to_app
			end

			def applicable(request)
				return request.path.index(@filter) != nil
			end

			def call(env)
				request = Rack::Request.new(env)

				if applicable(request)
					@process.call(env)
				else
					@app.call(env)
				end
			end
		end

	end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
utopia-0.9.58 lib/utopia/middleware/filter.rb
utopia-0.9.57 lib/utopia/middleware/filter.rb
utopia-0.9.56 lib/utopia/middleware/filter.rb
utopia-0.9.55 lib/utopia/middleware/filter.rb
utopia-0.9.54 lib/utopia/middleware/filter.rb
utopia-0.9.53 lib/utopia/middleware/filter.rb
utopia-0.9.52 lib/utopia/middleware/filter.rb
utopia-0.9.51 lib/utopia/middleware/filter.rb
utopia-0.9.50 lib/utopia/middleware/filter.rb
utopia-0.9.49 lib/utopia/middleware/filter.rb
utopia-0.9.48 lib/utopia/middleware/filter.rb
utopia-0.9.47 lib/utopia/middleware/filter.rb
utopia-0.9.46 lib/utopia/middleware/filter.rb
utopia-0.9.45 lib/utopia/middleware/filter.rb
utopia-0.9.43 lib/utopia/middleware/filter.rb
utopia-0.9.42 lib/utopia/middleware/filter.rb
utopia-0.9.41 lib/utopia/middleware/filter.rb
utopia-0.9.40 lib/utopia/middleware/filter.rb