Class: SoberSwag::Reporting::Report::Base
- Inherits:
-
Object
- Object
- SoberSwag::Reporting::Report::Base
- Defined in:
- lib/sober_swag/reporting/report/base.rb
Overview
Base class for SoberSwag reports.
These reports are what make these serializers and parsers reporting: they provide errors. For outputs, these are errors encountered during serialization, IE, places where we lied about what type we were going to serialize. This is mostly used for testing.
For parsers, these are encountered during parsing. This can be easily converted into a hash of JSON path objects to individual errors, enabling developers to more easily see what's gone wrong.
Direct Known Subclasses
Instance Method Summary collapse
- #each_error ⇒ Object
-
#full_errors ⇒ Array<[String]>
An array of error paths and error components, in the form of:.
-
#path_hash ⇒ Hash<String,Array<String>>
Get a hash where each key is a JSON path, and each value is an array of errors for that path.
Instance Method Details
#each_error {|path, val| ... } ⇒ Object #each_error ⇒ Enumerable<String, String>
51 52 53 |
# File 'lib/sober_swag/reporting/report/base.rb', line 51 def each_error return enum_for(:each_error) unless block_given? end |
#full_errors ⇒ Array<[String]>
Returns An array of error paths and error components, in the form of:
[
'foo.bar: was bad',
'foo.bar: was even worse'
]
```.
26 27 28 29 30 |
# File 'lib/sober_swag/reporting/report/base.rb', line 26 def full_errors each_error.map do |k, v| [k, v].reject(&:blank?).join(': ') end end |
#path_hash ⇒ Hash<String,Array<String>>
Get a hash where each key is a JSON path, and each value is an array of errors for that path.
35 36 37 38 39 40 41 |
# File 'lib/sober_swag/reporting/report/base.rb', line 35 def path_hash Hash.new { |h, k| h[k] = [] }.tap do |hash| each_error do |k, v| hash["$#{k}"] << v end end end |