Class: Airspace::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/airspace/key.rb

Overview

This class understands how to build keys and subkeys for storing data inside Redis.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, prefix: '') ⇒ Key

Returns a new instance of Key.



19
20
21
22
# File 'lib/airspace/key.rb', line 19

def initialize(id, prefix: '')
  @id     = id.to_s
  @prefix = prefix.to_s
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/airspace/key.rb', line 17

def id
  @id
end

#prefixObject (readonly)

Returns the value of attribute prefix.



17
18
19
# File 'lib/airspace/key.rb', line 17

def prefix
  @prefix
end

Instance Method Details

#chunk(index) ⇒ Object



31
32
33
# File 'lib/airspace/key.rb', line 31

def chunk(index)
  [root, index].join(SEPARATOR_CHAR)
end

#rootObject Also known as: to_s



24
25
26
27
28
# File 'lib/airspace/key.rb', line 24

def root
  return id if prefix.empty?

  [prefix, id].join(SEPARATOR_CHAR)
end