Class: FDB::DirectorySubspace

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

Direct Known Subclasses

DirectoryPartition

Instance Attribute Summary collapse

Attributes inherited from Subspace

#raw_prefix

Instance Method Summary collapse

Methods inherited from Subspace

#[], #as_foundationdb_key, #contains?, #key, #pack, #range, #subspace, #unpack

Constructor Details

#initialize(path, prefix, directory_layer = FDB::directory, layer = '') ⇒ DirectorySubspace

Returns a new instance of DirectorySubspace.



501
502
503
504
505
506
# File 'lib/fdbdirectory.rb', line 501

def initialize(path, prefix, directory_layer=FDB::directory, layer='')
  super([], prefix)
  @path = path
  @layer = layer
  @directory_layer = directory_layer
end

Instance Attribute Details

#directory_layerObject (readonly)

Returns the value of attribute directory_layer.



516
517
518
# File 'lib/fdbdirectory.rb', line 516

def directory_layer
  @directory_layer
end

Instance Method Details

#create(db_or_tr, name_or_path, options = {}) ⇒ Object



528
529
530
531
# File 'lib/fdbdirectory.rb', line 528

def create(db_or_tr, name_or_path, options={})
  path = tuplify_path(name_or_path)
  @directory_layer.create(db_or_tr, partition_subpath(path), options)
end

#create_or_open(db_or_tr, name_or_path, options = {}) ⇒ Object



518
519
520
521
# File 'lib/fdbdirectory.rb', line 518

def create_or_open(db_or_tr, name_or_path, options={})
  path = tuplify_path(name_or_path)
  @directory_layer.create_or_open(db_or_tr, partition_subpath(path), options)
end

#exists?(db_or_tr, name_or_path = []) ⇒ Boolean

Returns:

  • (Boolean)


566
567
568
569
570
# File 'lib/fdbdirectory.rb', line 566

def exists?(db_or_tr, name_or_path=[])
  path = tuplify_path(name_or_path)
  directory_layer = get_layer_for_path(path)
  directory_layer.exists?(db_or_tr, partition_subpath(path, directory_layer))
end

#layerObject



512
513
514
# File 'lib/fdbdirectory.rb', line 512

def layer
  return @layer.dup
end

#list(db_or_tr, name_or_path = []) ⇒ Object



533
534
535
536
# File 'lib/fdbdirectory.rb', line 533

def list(db_or_tr, name_or_path=[])
  path = tuplify_path(name_or_path)
  @directory_layer.list(db_or_tr, partition_subpath(path))
end

#move(db_or_tr, old_name_or_path, new_name_or_path) ⇒ Object



538
539
540
541
542
# File 'lib/fdbdirectory.rb', line 538

def move(db_or_tr, old_name_or_path, new_name_or_path)
  old_path = tuplify_path(old_name_or_path)
  new_path = tuplify_path(new_name_or_path)
  @directory_layer.move(db_or_tr, partition_subpath(old_path), partition_subpath(new_path))
end

#move_to(db_or_tr, new_absolute_name_or_path) ⇒ Object

Raises:

  • (ArgumentError)


544
545
546
547
548
549
550
551
552
# File 'lib/fdbdirectory.rb', line 544

def move_to(db_or_tr, new_absolute_name_or_path)
  directory_layer = get_layer_for_path([])
  new_absolute_path = directory_layer.send(:to_unicode_path, new_absolute_name_or_path)
  partition_len = directory_layer.path.length
  partition_path = new_absolute_path[0...partition_len]
  raise ArgumentError, 'Cannot move between partitions.' if partition_path != directory_layer.path
  directory_layer.move(db_or_tr, @path[partition_len..-1], 
                        new_absolute_path[partition_len..-1])
end

#open(db_or_tr, name_or_path, options = {}) ⇒ Object



523
524
525
526
# File 'lib/fdbdirectory.rb', line 523

def open(db_or_tr, name_or_path, options={})
  path = tuplify_path(name_or_path)
  @directory_layer.open(db_or_tr, partition_subpath(path), options)
end

#pathObject



508
509
510
# File 'lib/fdbdirectory.rb', line 508

def path
  return @path.dup
end

#remove(db_or_tr, name_or_path = []) ⇒ Object



554
555
556
557
558
# File 'lib/fdbdirectory.rb', line 554

def remove(db_or_tr, name_or_path=[])
  path = tuplify_path(name_or_path)
  directory_layer = get_layer_for_path(path)
  directory_layer.remove(db_or_tr, partition_subpath(path, directory_layer))
end

#remove_if_exists(db_or_tr, name_or_path = []) ⇒ Object



560
561
562
563
564
# File 'lib/fdbdirectory.rb', line 560

def remove_if_exists(db_or_tr, name_or_path=[])
  path = tuplify_path(name_or_path)
  directory_layer = get_layer_for_path(path)
  directory_layer.remove_if_exists(db_or_tr, partition_subpath(path, directory_layer))
end