Class: WebFunction::DocumentedError
- Inherits:
-
Object
- Object
- WebFunction::DocumentedError
- Defined in:
- lib/web_function/documented_error.rb
Overview
Represents an error definition as described in a Web Function package.
An error definition documents the possible errors that an endpoint might return, including a machine-readable error code and a human-readable description.
See the [error definition documentation] on the Web Function website for more details, including recognized keys and usage recommendations.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
The machine-readable code of the error.
-
#docs ⇒ String
readonly
The documentation of the error.
Class Method Summary collapse
-
.from_array(errors) ⇒ Array<DocumentedError>
Creates a new DocumentedError from an array of hashes.
-
.from_hash(error) ⇒ DocumentedError
Creates a new DocumentedError from a hash.
Instance Method Summary collapse
-
#initialize(code:, docs: nil) ⇒ DocumentedError
constructor
A new instance of DocumentedError.
Constructor Details
#initialize(code:, docs: nil) ⇒ DocumentedError
Returns a new instance of DocumentedError.
15 16 17 18 |
# File 'lib/web_function/documented_error.rb', line 15 def initialize(code:, docs: nil) @code = code @docs = docs.to_s end |
Instance Attribute Details
#code ⇒ String (readonly)
The machine-readable code of the error.
59 60 61 |
# File 'lib/web_function/documented_error.rb', line 59 def code @code end |
#docs ⇒ String (readonly)
The documentation of the error.
65 66 67 |
# File 'lib/web_function/documented_error.rb', line 65 def docs @docs end |
Class Method Details
.from_array(errors) ⇒ Array<DocumentedError>
Creates a new DocumentedError from an array of hashes. Uses from_hash under the hood.
48 49 50 51 52 |
# File 'lib/web_function/documented_error.rb', line 48 def from_array(errors) Utils.normalize_array errors do |error| from_hash(error) end end |
.from_hash(error) ⇒ DocumentedError
Creates a new DocumentedError from a hash.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/web_function/documented_error.rb', line 27 def from_hash(error) unless error.is_a?(Hash) return end unless error["code"] return end new( code: error["code"], docs: error["docs"], ) end |