Sha256: 499087c57f2a0c58f50a58f03204426c53105e08f147b287937cf2ac7cd804cf

Contents?: true

Size: 1.25 KB

Versions: 55

Compression:

Stored size: 1.25 KB

Contents

module PactBroker
  module Api
    module Contracts
      module DryValidationWorkarounds
        extend self

        # I just cannot seem to get the validation to stop on the first error.
        # If one rule fails, they all come back failed, and it's driving me nuts.
        # Why on earth would I want that behaviour?
        def select_first_message(messages)
          messages.each_with_object({}) do | (key, value), new_messages |
            new_messages[key] = [value.first]
          end
        end

        def flatten_array_of_hashes(array_of_hashes)
          new_messages = array_of_hashes.collect do | index, hash |
            hash.values.flatten.collect { | text | "#{text} at index #{index}"}
          end.flatten
        end

        def flatten_indexed_messages(messages)
          if messages.values.any?{ | value | is_indexed_structure?(value) }
            messages.each_with_object({}) do | (key, value), new_messages |
              new_messages[key] = is_indexed_structure?(value) ? flatten_array_of_hashes(value) : value
            end
          else
            messages
          end
        end

        def is_indexed_structure?(thing)
          thing.is_a?(Hash) && thing.keys.first.is_a?(Integer)
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.79.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.78.1 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.78.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.77.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.76.2 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.76.1 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.76.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.75.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.74.1 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.74.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.73.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.72.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.71.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.70.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.69.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.68.1 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.68.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.67.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb
pact_broker-2.66.0 lib/pact_broker/api/contracts/dry_validation_workarounds.rb