Sha256: 3f458f8c84f4ebefcfa1a3a513c2b178c301d945bb6343beac0bb14ec1831b3c

Contents?: true

Size: 806 Bytes

Versions: 20

Compression:

Stored size: 806 Bytes

Contents

require 'reform'
require 'reform/contract'
require 'net/http'

module PactBroker
  module Api
    module Contracts

      module RequestValidations
        def method_is_valid
          if http_method && !valid_method?
            errors.add(:method, "is not a recognised HTTP method")
          end
        end

        def valid_method?
          Net::HTTP.const_defined?(http_method.capitalize)
        end

        def url_is_valid
          if url && !url_valid?
            errors.add(:url, "is not a valid URL eg. http://example.org")
          end
        end

        def url_valid?
          uri && uri.scheme && uri.host
        end

        def uri
          begin
            URI(url)
          rescue URI::InvalidURIError
            nil
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
pact_broker-1.14.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.13.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.12.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.11.2 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.11.1 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.11.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.10.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.9.3 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.9.2 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.9.1 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.9.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.9.0.rc1 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.8.1 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.8.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.7.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.6.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.5.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.4.0 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.3.2.rc1 lib/pact_broker/api/contracts/request_validations.rb
pact_broker-1.3.1 lib/pact_broker/api/contracts/request_validations.rb