Class: Sbmt::Outbox::V2::RedisJob
- Inherits:
-
Object
- Object
- Sbmt::Outbox::V2::RedisJob
- Defined in:
- lib/sbmt/outbox/v2/redis_job.rb
Constant Summary collapse
- GENERIC_SEPARATOR =
":"
- IDS_SEPARATOR =
","
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bucket, ids, timestamp = Time.current.to_i) ⇒ RedisJob
constructor
A new instance of RedisJob.
- #serialize ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bucket, ids, timestamp = Time.current.to_i) ⇒ RedisJob
Returns a new instance of RedisJob.
12 13 14 15 16 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 12 def initialize(bucket, ids, = Time.current.to_i) @bucket = bucket @ids = ids @timestamp = end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 7 def bucket @bucket end |
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 7 def ids @ids end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 7 def @timestamp end |
Class Method Details
.deserialize!(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 26 def self.deserialize!(value) raise "invalid data type: string is required" unless value.is_a?(String) bucket, ts_utc, ids_str, _ = value.split(GENERIC_SEPARATOR) raise "invalid data format: bucket or ids are not valid" if bucket.blank? || ts_utc.blank? || ids_str.blank? ts = ts_utc.to_i ids = ids_str.split(IDS_SEPARATOR).map(&:to_i) raise "invalid data format: IDs are empty" if ids.blank? new(bucket, ids, ts) end |
Instance Method Details
#serialize ⇒ Object
22 23 24 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 22 def serialize [bucket, , ids.join(IDS_SEPARATOR)].join(GENERIC_SEPARATOR) end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/sbmt/outbox/v2/redis_job.rb', line 18 def to_s serialize end |