Class: FDB::Subspace

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

Direct Known Subclasses

DirectorySubspace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix_tuple = [], raw_prefix = '') ⇒ Subspace

Returns a new instance of Subspace.



32
33
34
# File 'lib/fdbsubspace.rb', line 32

def initialize(prefix_tuple=[], raw_prefix='')
  @raw_prefix = raw_prefix.dup.force_encoding('BINARY') + FDB::Tuple.pack(prefix_tuple)
end

Instance Attribute Details

#raw_prefixObject (readonly)

Returns the value of attribute raw_prefix.



35
36
37
# File 'lib/fdbsubspace.rb', line 35

def raw_prefix
  @raw_prefix
end

Instance Method Details

#[](name) ⇒ Object



37
38
39
# File 'lib/fdbsubspace.rb', line 37

def [](name)
  Subspace.new([name], @raw_prefix)
end

#as_foundationdb_keyObject



63
64
65
# File 'lib/fdbsubspace.rb', line 63

def as_foundationdb_key
  key
end

#contains?(key) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/fdbsubspace.rb', line 59

def contains?(key)
  key.start_with? @raw_prefix
end

#keyObject



41
42
43
# File 'lib/fdbsubspace.rb', line 41

def key
  @raw_prefix
end

#pack(tuple) ⇒ Object



45
46
47
# File 'lib/fdbsubspace.rb', line 45

def pack(tuple)
  @raw_prefix + FDB::Tuple.pack(tuple)
end

#range(tuple = []) ⇒ Object



54
55
56
57
# File 'lib/fdbsubspace.rb', line 54

def range(tuple=[])
  rng = FDB::Tuple.range(tuple)
  [@raw_prefix + rng[0], @raw_prefix + rng[1]]
end

#subspace(tuple) ⇒ Object



67
68
69
# File 'lib/fdbsubspace.rb', line 67

def subspace(tuple)
  Subspace.new(tuple, @raw_prefix)
end

#unpack(key) ⇒ Object

Raises:

  • (ArgumentError)


49
50
51
52
# File 'lib/fdbsubspace.rb', line 49

def unpack(key)
  raise ArgumentError, 'Cannot unpack key that is not in subspace.' if not contains? key
  FDB::Tuple.unpack(key[@raw_prefix.length..-1])
end