Class: WebTrap::Shared::RackApp Private

Inherits:
Object
  • Object
show all
Defined in:
lib/webtrap/shared/rack_app.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Constructor Details

#initialize(validators) ⇒ RackApp

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Examples:

Intercept any request

require "webmock"
# ...
WebMock::API.stub_request(:any, /.*/).to_rack RackApp.new(validators)

Parameters:

  • validators (Array)

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



15
16
17
# File 'lib/webtrap/shared/rack_app.rb', line 15

def initialize(validators)
  @validators = validators
end

Instance Method Details

#call(request) ⇒ Array<Fixnum, Hash, Array>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle an HTTP request.

Parameters:

  • request (Hash)

    Request environment, as defined by the Rack spec.

Returns:

  • (Array<Fixnum, Hash, Array>)

    An empty successful response.

See Also:



27
28
29
30
31
32
# File 'lib/webtrap/shared/rack_app.rb', line 27

def call(request)
  @validators.find do |v|
    v.validate(request).failed?
  end
  [200, {}, []]
end