class StatelyDB::KeyPath

KeyPath is a helper class for constructing key paths.

def self.to_key_id(value)

Returns:
  • (String) -

Parameters:
  • value (String, StatelyDB::UUID, #to_s) -- The value to convert to a key id.
def self.to_key_id(value)
  if value.is_a?(StatelyDB::UUID)
    value.to_base64
  elsif value.is_a?(String) && value.encoding == Encoding::BINARY
    [value].pack("m0").tr("=", "").tr("+/", "-_")
  else
    # Any other value is just converted to a string
    value.to_s.gsub("/", "%/")
  end
end

def self.with(namespace, identifier = nil)

Returns:
  • (StatelyDB::KeyPath) -

Parameters:
  • identifier (String, StatelyDB::UUID, #to_s) --
  • namespace (String) --
def self.with(namespace, identifier = nil)
  new.with(namespace, identifier)
end

def initialize

def initialize
  super
  @path = []
end

def inspect

Returns:
  • (String) -
def inspect
  to_str
end

def to_s

Returns:
  • (String) -
def to_s
  to_str
end

def to_str

Returns:
  • (String) -
def to_str
  "/".dup.concat(@path.join("/"))
end

def with(namespace, identifier = nil)

Returns:
  • (StatelyDB::KeyPath) -

Parameters:
  • identifier (String, StatelyDB::UUID, #to_s) --
  • namespace (String) --
def with(namespace, identifier = nil)
  if identifier.nil?
    @path << namespace
    return self
  end
  @path << "#{namespace}-#{self.class.to_key_id(identifier)}"
  self
end