class WebTrap::Shared::RackApp

@api private Rack applications used to intercept HTTP requests and apply a set of validators on them.

Public Class Methods

new(validators) click to toggle source

Instantiate a new Rack application with the provided set of validators.

@param validators [Array]

Set of validators used on the intercepted request to assert its validity.

@example Intercept any request

require "webmock"
# ...
WebMock::API.stub_request(:any, /.*/).to_rack RackApp.new(validators)
# File lib/webtrap/shared/rack_app.rb, line 15
def initialize(validators)
  @validators = validators
end

Public Instance Methods

call(request) click to toggle source

Handle an HTTP request.

@param request [Hash]

Request environment, as defined by the Rack spec.

@return [Array<Fixnum, Hash, Array>]

An empty successful response.

@see www.rubydoc.info/github/rack/rack/master/file/SPEC

Rack spec
# File lib/webtrap/shared/rack_app.rb, line 27
def call(request)
  @validators.find do |v|
    v.validate(request).failed?
  end
  [200, {}, []]
end