Class: NextStation::Operation::ErrorDefinition
- Inherits:
-
Object
- Object
- NextStation::Operation::ErrorDefinition
- Defined in:
- lib/next_station/operation/errors.rb
Overview
Defines an error with its messages and optional help URL.
Instance Attribute Summary collapse
-
#help_url(url = nil) ⇒ String?
readonly
Sets or returns the help URL for the error.
-
#messages ⇒ Hash
readonly
Map of locales to message templates.
-
#type ⇒ Symbol
readonly
The error type.
Instance Method Summary collapse
-
#initialize(type) ⇒ ErrorDefinition
constructor
A new instance of ErrorDefinition.
-
#message(hashes) ⇒ Object
Adds localized messages for the error.
-
#resolve_message(lang, msg_keys) ⇒ String
Resolves the error message for a given language.
-
#validate! ⇒ Object
Validates whether the error definition is complete.
Constructor Details
#initialize(type) ⇒ ErrorDefinition
Returns a new instance of ErrorDefinition.
38 39 40 41 42 |
# File 'lib/next_station/operation/errors.rb', line 38 def initialize(type) @type = type @messages = {} @help_url = nil end |
Instance Attribute Details
#help_url(url = nil) ⇒ String? (readonly)
Sets or returns the help URL for the error.
35 36 37 |
# File 'lib/next_station/operation/errors.rb', line 35 def help_url @help_url end |
#messages ⇒ Hash (readonly)
Returns Map of locales to message templates.
33 34 35 |
# File 'lib/next_station/operation/errors.rb', line 33 def @messages end |
#type ⇒ Symbol (readonly)
Returns The error type.
31 32 33 |
# File 'lib/next_station/operation/errors.rb', line 31 def type @type end |
Instance Method Details
#message(hashes) ⇒ Object
Adds localized messages for the error.
46 47 48 |
# File 'lib/next_station/operation/errors.rb', line 46 def (hashes) @messages.merge!(hashes) end |
#resolve_message(lang, msg_keys) ⇒ String
Resolves the error message for a given language.
70 71 72 73 |
# File 'lib/next_station/operation/errors.rb', line 70 def (lang, msg_keys) template = @messages[lang.to_sym] || @messages[:en] template % msg_keys end |
#validate! ⇒ Object
Validates whether the error definition is complete.
62 63 64 |
# File 'lib/next_station/operation/errors.rb', line 62 def validate! raise "English message is required for error type: #{@type}" unless @messages[:en] end |