Class: Hyperion::Key
- Inherits:
-
Object
- Object
- Hyperion::Key
- Defined in:
- lib/hyperion/key.rb
Class Method Summary collapse
- .compose_key(kind, id = nil) ⇒ Object
- .decode_key(value) ⇒ Object
- .decompose_key(key) ⇒ Object
- .encode_key(value) ⇒ Object
- .generate_id ⇒ Object
Class Method Details
.compose_key(kind, id = nil) ⇒ Object
16 17 18 19 |
# File 'lib/hyperion/key.rb', line 16 def compose_key(kind, id=nil) _id = id.nil? || id.to_s.strip == "" ? generate_id : id.to_s encode_key("#{encode_key(kind.to_s)}:#{_id}") end |
.decode_key(value) ⇒ Object
12 13 14 |
# File 'lib/hyperion/key.rb', line 12 def decode_key(value) decode(denormalize(value)) end |
.decompose_key(key) ⇒ Object
21 22 23 24 |
# File 'lib/hyperion/key.rb', line 21 def decompose_key(key) kind, sep, id = decode_key(key).partition(/:/) [decode_key(kind), id] end |
.encode_key(value) ⇒ Object
8 9 10 |
# File 'lib/hyperion/key.rb', line 8 def encode_key(value) normalize(encode(value)) end |
.generate_id ⇒ Object
26 27 28 |
# File 'lib/hyperion/key.rb', line 26 def generate_id UUIDTools::UUID.random_create.to_s.gsub(/-/, '') end |