Sha256: 1a8c5ecaafc13ce622646adb5f5adbb4fb66b90cbbe5a253e4e06d458d73e66a
Contents?: true
Size: 776 Bytes
Versions: 15
Compression:
Stored size: 776 Bytes
Contents
# frozen_string_literal: true class StringHack class FastIdList def self.from_array(array) new(",#{array.join(",")},") end def self.from_string(string) new(string) end def initialize(packed) @packed = packed end def include?(id) @packed.include?(",#{id},") end def to_s @packed end end def initialize @oj_options = { mode: :compat } end def encode(hash) if user_ids = hash["user_ids"] hash["user_ids"] = FastIdList.from_array(user_ids).to_s end ::Oj.dump(hash, @oj_options) end def decode(payload) result = ::Oj.load(payload, @oj_options) if str = result["user_ids"] result["user_ids"] = FastIdList.from_string(str) end result end end
Version data entries
15 entries across 15 versions & 1 rubygems