Class: Openapi3Parser::Validation::ErrorCollection
- Inherits:
-
Object
- Object
- Openapi3Parser::Validation::ErrorCollection
- Includes:
- Enumerable
- Defined in:
- lib/openapi3_parser/validation/error_collection.rb
Overview
An immutable collection of Validation::Error objects
Defined Under Namespace
Classes: LocationTypeGroup
Instance Attribute Summary collapse
-
#errors ⇒ Array<Validation::Error>
(also: #to_a)
readonly
The current value of errors.
Class Method Summary collapse
-
.combine(errors, other_errors) ⇒ ErrorCollection
Combines ErrorCollection objects or arrays of Validation::Error objects.
Instance Method Summary collapse
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#group_errors ⇒ Array<LocationTypeGroup]
Group errors by those in the same location for the same node.
-
#initialize(errors = []) ⇒ ErrorCollection
constructor
A new instance of ErrorCollection.
- #inspect ⇒ String
-
#to_h ⇒ Hash
Return a hash structure where the location is key and the errors are values.
Constructor Details
#initialize(errors = []) ⇒ ErrorCollection
Returns a new instance of ErrorCollection.
22 23 24 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 22 def initialize(errors = []) @errors = errors.freeze end |
Instance Attribute Details
#errors ⇒ Array<Validation::Error> (readonly) Also known as: to_a
Returns the current value of errors.
7 8 9 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 7 def errors @errors end |
Class Method Details
.combine(errors, other_errors) ⇒ ErrorCollection
Combines ErrorCollection objects or arrays of Validation::Error objects
14 15 16 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 14 def self.combine(errors, other_errors) new(errors.to_a + other_errors.to_a) end |
Instance Method Details
#each ⇒ Object
30 31 32 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 30 def each(&) errors.each(&) end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 26 def empty? errors.empty? end |
#group_errors ⇒ Array<LocationTypeGroup]
Group errors by those in the same location for the same node
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 37 def group_errors grouped = group_by do |e| [e.source_location.to_s, e.for_type] end grouped.map do |_, errors| LocationTypeGroup.new(errors[0].source_location, errors[0].for_type, errors) end end |
#inspect ⇒ String
65 66 67 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 65 def inspect "#{self.class.name}(errors: #{to_h})" end |
#to_h ⇒ Hash
Return a hash structure where the location is key and the errors are values
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/openapi3_parser/validation/error_collection.rb', line 53 def to_h grouped = group_errors.group_by { |g| g.source_location.to_s } grouped.each_with_object({}) do |(_, items), memo| items.each do |item| key = item.location_summary(with_type: items.count > 1) memo[key] = memo.fetch(key, []) + item.errors.map(&:to_s) end end end |