Skip to content

Ruby

Our API Reference has generic examples in every supported language, and we strive to make the experience of each SDK very similar. However, there are some things specific to the Ruby SDK that we want to call out here.

Types

We provide types for both our Ruby SDK and generated Ruby code in both RBS and Sorbet flavors.

Key Path Helpers

The StatelyDB::KeyPath class can be used to safely construct key paths:

key_path = StatelyDB::KeyPath.with('movie', result.id)

This will produce a key path like /movie-p05olqcFSfC6zOqEojxT9g, correctly encoding a UUID ID. You can append more segments onto an existing KeyPath using with:

key_path = StatelyDB::KeyPath.with('movie', result.id).with('actor', actor.id)

Checking an Item’s Type

Many client APIs return a list of items, but you want to know exactly what type each item is.

if item.is_a? StatelyDB::Types::Movie
# it's a movie
end
case item
when StatelyDB::Types::Movie
# it's a movie
when StatelyDB::Types::Character
# it's a character
end

UUIDs

UUIDs use the StatelyDB::UUID type, which can be constructed from a standard 36-byte UUID string using StatelyDB::UUID.parse(input). to_s produces that output, while to_base64 produces the Stately base64 version.

Enums

Enums are generated as modules under StatelyDB::Types::Enum. Each enum module has a constant for each value, plus a from_int class method that can be used to validate that a value exists in the enum.