Class: Karafka::Core::Contractable::Result
- Inherits:
-
Object
- Object
- Karafka::Core::Contractable::Result
- Defined in:
- lib/karafka/core/contractable/result.rb
Overview
Representation of a validaton result with resolved error messages
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(errors, contract) ⇒ Result
constructor
Builds a result object and remaps (if needed) error keys to proper error messages.
-
#success? ⇒ Boolean
True if no errors.
Constructor Details
#initialize(errors, contract) ⇒ Result
Builds a result object and remaps (if needed) error keys to proper error messages
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/karafka/core/contractable/result.rb', line 19 def initialize(errors, contract) # Short track to skip object allocation for the happy path if errors.empty? @errors = EMPTY_HASH return end hashed = {} errors.each do |error| scope = error.first.map(&:to_s).join('.').to_sym # This will allow for usage of custom messages instead of yaml keys if needed hashed[scope] = if error.last.is_a?(String) error.last else (contract, scope, error.last) end end @errors = hashed end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/karafka/core/contractable/result.rb', line 8 def errors @errors end |
Instance Method Details
#success? ⇒ Boolean
Returns true if no errors.
43 44 45 |
# File 'lib/karafka/core/contractable/result.rb', line 43 def success? errors.empty? end |