Class: Airspace::Key
- Inherits:
-
Object
- Object
- Airspace::Key
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #chunk(index) ⇒ Object
-
#initialize(id, prefix: '') ⇒ Key
constructor
A new instance of Key.
- #root ⇒ Object (also: #to_s)
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/airspace/key.rb', line 17 def id @id end |
#prefix ⇒ Object (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 |
#root ⇒ Object 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 |