Class: Sbmt::Outbox::V2::RedisItemMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/sbmt/outbox/v2/redis_item_meta.rb

Constant Summary collapse

CURRENT_VERSION =
1
MAX_ERROR_LEN =
200

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors_count:, error_msg:, timestamp: Time.current.to_i, version: CURRENT_VERSION) ⇒ 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
  @timestamp = timestamp
  @version = version
end

Instance Attribute Details

#error_msgObject (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_countObject (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

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 7

def timestamp
  @timestamp
end

#versionObject (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

#serializeObject



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: timestamp,
    errors_count: errors_count,
    error_msg: error_msg.slice(0, MAX_ERROR_LEN)
  })
end

#to_sObject



19
20
21
# File 'lib/sbmt/outbox/v2/redis_item_meta.rb', line 19

def to_s
  serialize
end