Class: Asynchronic::DataStore::Key

Inherits:
String
  • Object
show all
Defined in:
lib/asynchronic/data_store/key.rb

Constant Summary collapse

SEPARATOR =
'|'

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

#sectionsObject



19
20
21
# File 'lib/asynchronic/data_store/key.rb', line 19

def sections
  split SEPARATOR
end