Module: BasedUUID
- Defined in:
- lib/based_uuid.rb,
lib/based_uuid/version.rb,
lib/based_uuid/base32_uuid.rb,
lib/based_uuid/has_based_uuid.rb
Defined Under Namespace
Modules: HasBasedUUID, ModelExtensions
Classes: Base32UUID, Error
Constant Summary
collapse
- VERSION =
"0.6.4".freeze
Class Method Summary
collapse
Class Method Details
.decode(token) ⇒ Object
40
41
42
43
|
# File 'lib/based_uuid.rb', line 40
def decode(token)
_, uuid_base32 = split(token)
Base32UUID.decode(uuid_base32)
end
|
.encode(uuid:, prefix: nil) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/based_uuid.rb', line 33
def encode(uuid:, prefix: nil)
uuid_base32 = Base32UUID.encode(uuid)
return uuid_base32 unless prefix
"#{prefix}#{delimiter}#{uuid_base32}"
end
|
.find(token) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/based_uuid.rb', line 13
def find(token)
prefix, = split(token)
registered_models.fetch(prefix.to_sym).find_by_based_uuid(token)
rescue KeyError
raise Error, "Unable to find model for `#{prefix}`. Registered prefixes: #{registered_models.keys.join(", ")}"
end
|
.register_model_prefix(prefix, model) ⇒ Object
20
21
22
|
# File 'lib/based_uuid.rb', line 20
def register_model_prefix(prefix, model)
registered_models[prefix] = model
end
|
.registered_models ⇒ Object
24
25
26
|
# File 'lib/based_uuid.rb', line 24
def registered_models
@registered_models ||= {}
end
|
.split(token) ⇒ Object
28
29
30
31
|
# File 'lib/based_uuid.rb', line 28
def split(token)
prefix, _, uuid_base32 = token.to_s.rpartition(delimiter)
[prefix.presence, uuid_base32]
end
|