class FDB::DirectorySubspace

def create(db_or_tr, name_or_path, options={})

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

def create_or_open(db_or_tr, name_or_path, options={})

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

def exists?(db_or_tr, name_or_path=[])

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

def get_layer_for_path(path)

def get_layer_for_path(path)
  @directory_layer
end

def initialize(path, prefix, directory_layer=FDB::directory, layer='')

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

def layer

def layer
  return @layer.dup
end

def list(db_or_tr, name_or_path=[])

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

def move(db_or_tr, old_name_or_path, new_name_or_path)

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

def move_to(db_or_tr, new_absolute_name_or_path)

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

def open(db_or_tr, name_or_path, options={})

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

def partition_subpath(path, directory_layer = @directory_layer)

def partition_subpath(path, directory_layer = @directory_layer)
  self.path[directory_layer.path.length..-1] + path
end

def path

def path
  return @path.dup
end

def remove(db_or_tr, name_or_path=[])

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

def remove_if_exists(db_or_tr, name_or_path=[])

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

def tuplify_path(path)

def tuplify_path(path)
  if path.is_a? String
    [path]
  else
    path
  end
end