Sha256: 872533c674d6ab80f19498d3870d3e7f60180513279a4b23e30ac7a0594a2cc7

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

require "pact_broker/services"
require "pact_broker/string_refinements"
require "pact_broker/configuration"
require "uri"

module PactBroker
  module Api
    module Contracts
      module ValidationHelpers
        extend self
        using PactBroker::StringRefinements

        def multiple_lines?(value)
          value && value.is_a?(String) && value.include?("\n")
        end

        def includes_space?(value)
          value && value.is_a?(String) && value.include?(" ")
        end

        # @return true if there is a value present, and it only contains whitespace
        def blank?(value)
          value&.blank?
        end

        # The tins gem has screwed up the present? method by not using refinements
        # Return true if the object is not nil, and if a String, is not blank.
        # @param [Object]
        def provided?(value)
          if value.is_a?(String)
            value.strip.size > 0
          else
            !value.nil?
          end
        end

        def not_provided?(value)
          !provided?(value)
        end

        def valid_url?(url)
          URI(url)
        rescue URI::InvalidURIError, ArgumentError
          false
        end

        def valid_http_method?(http_method)
          Net::HTTP.const_defined?(http_method.capitalize)
        rescue StandardError
          false
        end

        def pacticipant_with_name_exists?(value)
          PactBroker::Services.pacticipant_service.find_pacticipant_by_name(value)
        end

        def environment_with_name_exists?(value)
          PactBroker::Services.environment_service.find_by_name(value)
        end

        def valid_version_number?(value)
          if PactBroker.configuration.order_versions_by_date
            true
          else
            !!PactBroker.configuration.version_parser.call(value)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.111.0 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.109.1 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.109.0 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.108.0 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.107.1 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.107.0 lib/pact_broker/api/contracts/validation_helpers.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/api/contracts/validation_helpers.rb