Sha256: fbbfda369ae34d0fe601fc9086ef6fbc13fc4c1a5896c38b155af056e00c3a99

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

require 'reform'
require 'reform/form'

module PactBroker
  module Api
    module Contracts
      class WebhookContract < Reform::Form

        validation do
          configure do
            config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
          end

          required(:request).filled
          optional(:events).maybe(min_size?: 1)
        end

        property :request do
          property :url
          property :http_method

          validation do
            configure do
              config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)

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

              def valid_url?(value)
                uri = URI(value)
                uri.scheme && uri.host
              rescue URI::InvalidURIError
                false
              end
            end

            required(:http_method).filled(:valid_method?)
            required(:url).filled(:valid_url?)
          end
        end

        collection :events do
          property :name

          validation do
            required(:name).filled
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.19.2 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.19.1 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.19.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.18.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.17.1 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.17.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.16.1 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.16.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.15.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.14.0 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.13.1 lib/pact_broker/api/contracts/webhook_contract.rb
pact_broker-2.13.0 lib/pact_broker/api/contracts/webhook_contract.rb