Module: PactBroker::Api::Contracts::DryValidationWorkarounds
- Extended by:
- DryValidationWorkarounds
- Defined in:
- lib/pact_broker/api/contracts/dry_validation_workarounds.rb
Instance Method Summary collapse
- #flatten_array_of_hashes(array_of_hashes) ⇒ Object
- #flatten_indexed_messages(messages) ⇒ Object
- #is_indexed_structure?(thing) ⇒ Boolean
-
#select_first_message(messages) ⇒ Object
I just cannot seem to get the validation to stop on the first error.
Instance Method Details
#flatten_array_of_hashes(array_of_hashes) ⇒ Object
16 17 18 19 20 |
# 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 | hash.values.flatten.collect { | text | "#{text} at index #{index}"} end.flatten end |
#flatten_indexed_messages(messages) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/pact_broker/api/contracts/dry_validation_workarounds.rb', line 22 def () if .values.any?{ | value | is_indexed_structure?(value) } .each_with_object({}) do | (key, value), | [key] = is_indexed_structure?(value) ? flatten_array_of_hashes(value) : value end else end end |
#is_indexed_structure?(thing) ⇒ Boolean
32 33 34 |
# File 'lib/pact_broker/api/contracts/dry_validation_workarounds.rb', line 32 def is_indexed_structure?(thing) thing.is_a?(Hash) && thing.keys.first.is_a?(Integer) end |
#select_first_message(messages) ⇒ Object
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?
10 11 12 13 14 |
# File 'lib/pact_broker/api/contracts/dry_validation_workarounds.rb', line 10 def () .each_with_object({}) do | (key, value), | [key] = [value.first] end end |