Ruby SDK
The Ruby SDK (secretspec) is a thin client over the secretspec-ffi C ABI,
linked into a native C extension at build time. Resolution happens in the Rust
core, so the SDK inherits every provider with no Ruby-side logic.
Quick start
Section titled “Quick start”require "secretspec"
resolved = Secretspec::SecretSpec.builder
.with_provider("keyring://")
.with_profile("production")
.with_reason("boot web app")
.load
puts resolved.provider, resolved.profile
db = resolved.secrets["DATABASE_URL"]
puts db.get # the value, or the file path for as_path secrets
resolved.set_as_env! # export everything into ENV
A missing required secret raises Secretspec::MissingRequiredError; any other
failure raises Secretspec::Error (with a stable #kind).
Scopes (0.17+)
Section titled “Scopes (0.17+)”Use .with_scope("api") to resolve only a named [scopes.api] subset. The
selected name is available as resolved.scope and report.scope:
resolved = Secretspec::SecretSpec.builder.with_scope("api").load
Typed access (codegen)
Section titled “Typed access (codegen)”Generate typed classes with secretspec schema plus
quicktype, then build them from resolved.fields:
secretspec schema | quicktype -s schema --top-level SecretSpec --lang ruby -o secrets_gen.rbtyped = SecretSpec.from_dynamic!(resolved.fields) # typed, generated
puts typed.database_url
Native library
Section titled “Native library”The published platform gems bundle the secretspec-ffi archive and statically
link it into the mkmf extension at install time.
pkg-config (0.19+)
Section titled “pkg-config (0.19+)”To build against your own secretspec-ffi install instead, install it with
cargo-c and pass --enable-pkg-config:
bash secretspec-ffi/scripts/cinstall.sh "$PREFIX"PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" gem install secretspec -- --enable-pkg-configDynamic linking (0.19+)
Section titled “Dynamic linking (0.19+)”Drop --library-type staticlib from the install and the extension links the
shared library instead.