module PactBroker::Api::Contracts::DryValidationWorkarounds
Public Instance Methods
flatten_array_of_hashes(array_of_hashes)
click to toggle source
# File lib/pact_broker/api/contracts/dry_validation_workarounds.rb, line 16 def flatten_array_of_hashes(array_of_hashes) array_of_hashes.collect do | index, hash_or_array | array = hash_or_array.is_a?(Hash) ? hash_or_array.values.flatten : hash_or_array array.collect { | text | "#{text} at index #{index}"} end.flatten end
flatten_indexed_messages(messages)
click to toggle source
# File lib/pact_broker/api/contracts/dry_validation_workarounds.rb, line 23 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
is_indexed_structure?(thing)
click to toggle source
# File lib/pact_broker/api/contracts/dry_validation_workarounds.rb, line 33 def is_indexed_structure?(thing) thing.is_a?(Hash) && thing.keys.first.is_a?(Integer) end
select_first_message(messages)
click to toggle source
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?
# File lib/pact_broker/api/contracts/dry_validation_workarounds.rb, line 10 def select_first_message(messages) messages.each_with_object({}) do | (key, value), new_messages | new_messages[key] = [value.first] end end