Sha256: d887d3345bf52ebcd9ee06a78c8ab724b7f11c470fe755324b7dbe07d873b28c

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

# @api private
# Rack applications used to intercept HTTP requests and apply a set of
# validators on them.
class WebTrap::Shared::RackApp
  # 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)
  def initialize(validators)
    @validators = validators
  end

  # 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 http://www.rubydoc.info/github/rack/rack/master/file/SPEC
  #   Rack spec
  def call(request)
    @validators.find do |v|
      v.validate(request).failed?
    end
    [200, {}, []]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webtrap-0.1.1 lib/webtrap/shared/rack_app.rb
webtrap-0.1.0 lib/webtrap/shared/rack_app.rb