Class: ErrorNormalizer::Error
- Inherits:
-
Object
- Object
- ErrorNormalizer::Error
- Defined in:
- lib/error_normalizer/error.rb
Overview
Class Method Summary collapse
-
.===(other) ⇒ Boolean
Case equality check.
Instance Method Summary collapse
-
#initialize(error_key, message: nil, type: 'params', **payload) ⇒ Error
constructor
A new instance of Error.
-
#to_hash ⇒ Hash
Error Hash representation.
-
#to_json ⇒ String
Error JSON string representation.
Constructor Details
#initialize(error_key, message: nil, type: 'params', **payload) ⇒ Error
Returns a new instance of Error.
26 27 28 29 30 31 |
# File 'lib/error_normalizer/error.rb', line 26 def initialize(error_key, message: nil, type: 'params', **payload) @key = error_key = @type = type @payload = payload end |
Class Method Details
.===(other) ⇒ Boolean
Case equality check
35 36 37 38 39 40 41 |
# File 'lib/error_normalizer/error.rb', line 35 def self.===(other) return true if other.is_a?(Error) return false unless other.is_a?(Hash) h = other.transform_keys(&:to_s) h.key?('key') && h.key?('message') && h.key?('payload') && h.key?('type') end |
Instance Method Details
#to_hash ⇒ Hash
Returns error Hash representation.
44 45 46 47 48 49 50 51 |
# File 'lib/error_normalizer/error.rb', line 44 def to_hash { key: @key, message: , payload: payload, type: @type } end |
#to_json ⇒ String
Returns error JSON string representation.
54 55 56 |
# File 'lib/error_normalizer/error.rb', line 54 def to_json to_hash.to_json end |