module VWO::Common::UUIDUtils
Constants
- VWO_NAMESPACE
Public Class Methods
parse(obj)
click to toggle source
# File lib/vwo/common/uuid_utils.rb, line 15 def self.parse(obj) str = obj.to_s.sub(/\Aurn:uuid:/, '') str.gsub!(/[^0-9A-Fa-f]/, '') [str[0..31]].pack 'H*' end
uuid_v5(uuid_namespace, name)
click to toggle source
# File lib/vwo/common/uuid_utils.rb, line 21 def self.uuid_v5(uuid_namespace, name) uuid_namespace = parse(uuid_namespace) hash_class = ::Digest::SHA1 version = 5 hash = hash_class.new hash.update(uuid_namespace) hash.update(name) ary = hash.digest.unpack('NnnnnN') ary[2] = (ary[2] & 0x0FFF) | (version << 12) ary[3] = (ary[3] & 0x3FFF) | 0x8000 # rubocop:disable Lint/FormatString '%08x-%04x-%04x-%04x-%04x%08x' % ary # rubocop:enable Lint/FormatString end
Public Instance Methods
generate(namespace, name)
click to toggle source
Generated uuid from namespace and name, uses uuid5
@param :namespace Namespace @param[String) :name Name
@return Uuid, nil if any of the arguments is empty
# File lib/vwo/common/uuid_utils.rb, line 74 def generate(namespace, name) VWO::Common::UUIDUtils.uuid_v5(namespace, name) if name && namespace end
generator_for(user_id, account_id)
click to toggle source
Generates desired UUID
@param :user_id User identifier @param :account_id Account identifier
@return Desired UUID
# File lib/vwo/common/uuid_utils.rb, line 47 def generator_for(user_id, account_id) user_id = user_id.to_s account_id = account_id.to_s user_id_namespace = generate(VWO_NAMESPACE, account_id) uuid_for_account_user_id = generate(user_id_namespace, user_id) desired_uuid = uuid_for_account_user_id.delete('-').upcase VWO::CustomLogger.get_instance.log( LogLevelEnum::DEBUG, format( LogMessageEnum::DebugMessages::UUID_FOR_USER, file: FileNameEnum::UuidUtil, user_id: user_id, account_id: account_id, desired_uuid: desired_uuid ) ) desired_uuid end