Class: Asynchronic::DataStore::Key
- Inherits:
-
String
- Object
- String
- Asynchronic::DataStore::Key
- Defined in:
- lib/asynchronic/data_store/key.rb
Constant Summary collapse
- SEPARATOR =
'|'
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(key) ⇒ Key
constructor
A new instance of Key.
- #nested? ⇒ Boolean
- #remove_first(count = 1) ⇒ Object
- #remove_last(count = 1) ⇒ Object
- #sections ⇒ Object
Constructor Details
#initialize(key) ⇒ Key
Returns a new instance of Key.
11 12 13 |
# File 'lib/asynchronic/data_store/key.rb', line 11 def initialize(key) super key.to_s end |
Class Method Details
.[](key) ⇒ Object
7 8 9 |
# File 'lib/asynchronic/data_store/key.rb', line 7 def self.[](key) new key end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/asynchronic/data_store/key.rb', line 15 def [](key) self.class.new [self, key].join(SEPARATOR) end |
#nested? ⇒ Boolean
23 24 25 |
# File 'lib/asynchronic/data_store/key.rb', line 23 def nested? sections.count > 1 end |
#remove_first(count = 1) ⇒ Object
27 28 29 |
# File 'lib/asynchronic/data_store/key.rb', line 27 def remove_first(count=1) self.class.new sections[count..-1].join(SEPARATOR) end |
#remove_last(count = 1) ⇒ Object
31 32 33 |
# File 'lib/asynchronic/data_store/key.rb', line 31 def remove_last(count=1) self.class.new sections[0..-count-1].join(SEPARATOR) end |
#sections ⇒ Object
19 20 21 |
# File 'lib/asynchronic/data_store/key.rb', line 19 def sections split SEPARATOR end |