Class: Trane::ErrorsBuilder
- Inherits:
-
Object
- Object
- Trane::ErrorsBuilder
- Defined in:
- lib/trane/error_registry.rb
Overview
Builder for Trane.errors do ... end
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
-
#error(key, status_code:, description: nil) ⇒ Object
Accepts a Symbol, String (short name or FQDN), or Class.
-
#initialize ⇒ ErrorsBuilder
constructor
A new instance of ErrorsBuilder.
Constructor Details
#initialize ⇒ ErrorsBuilder
Returns a new instance of ErrorsBuilder.
19 20 21 |
# File 'lib/trane/error_registry.rb', line 19 def initialize @definitions = [] end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
17 18 19 |
# File 'lib/trane/error_registry.rb', line 17 def definitions @definitions end |
Instance Method Details
#error(key, status_code:, description: nil) ⇒ Object
Accepts a Symbol, String (short name or FQDN), or Class. When a Class is given, Class#name is used as the key.
25 26 27 28 |
# File 'lib/trane/error_registry.rb', line 25 def error(key, status_code:, description: nil) key_str = key.is_a?(Class) ? key.name : key.to_s @definitions << ErrorDefinition.new(key: key_str, status_code: status_code, description: description) end |