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:

1
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:

1
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.

1
if item.is_a? StatelyDB::Types::Movie
2
# it's a movie
3
end
4
5
case item
6
when StatelyDB::Types::Movie
7
# it's a movie
8
when StatelyDB::Types::Character
9
# it's a character
10
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.