Class: Sbmt::Outbox::V2::RedisItemMeta
- Inherits:
-
Object
- Object
- Sbmt::Outbox::V2::RedisItemMeta
- Defined in:
- lib/sbmt/outbox/v2/redis_item_meta.rb
Constant Summary collapse
- CURRENT_VERSION =
1- MAX_ERROR_LEN =
200
Instance Attribute Summary collapse
-
#error_msg ⇒ Object
readonly
Returns the value of attribute error_msg.
-
#errors_count ⇒ Object
readonly
Returns the value of attribute errors_count.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(errors_count:, error_msg:, timestamp: Time.current.to_i, version: CURRENT_VERSION) ⇒ RedisItemMeta
constructor
A new instance of RedisItemMeta.
- #serialize ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(errors_count:, error_msg:, timestamp: Time.current.to_i, version: CURRENT_VERSION) ⇒ RedisItemMeta
Returns a new instance of RedisItemMeta.
12 13 14 15 16 17 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 12 def initialize(errors_count:, error_msg:, timestamp: Time.current.to_i, version: CURRENT_VERSION) @errors_count = errors_count @error_msg = error_msg = @version = version end |
Instance Attribute Details
#error_msg ⇒ Object (readonly)
Returns the value of attribute error_msg.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 7 def error_msg @error_msg end |
#errors_count ⇒ Object (readonly)
Returns the value of attribute errors_count.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 7 def errors_count @errors_count end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 7 def end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 7 def version @version end |
Class Method Details
.deserialize!(value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 32 def self.deserialize!(value) raise "invalid data type: string is required" unless value.is_a?(String) data = JSON.parse!(value, max_nesting: 1) new( version: data["version"], timestamp: data["timestamp"].to_i, errors_count: data["errors_count"].to_i, error_msg: data["error_msg"] ) end |
Instance Method Details
#serialize ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 23 def serialize JSON.generate({ version: version, timestamp: , errors_count: errors_count, error_msg: error_msg.slice(0, MAX_ERROR_LEN) }) end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 19 def to_s serialize end |