Ruby OpenFeature provider
The Unleash OpenFeature Ruby provider lets Ruby applications evaluate Unleash feature flags through the OpenFeature API.
The provider wraps the Unleash Ruby SDK and uses the same backend SDK behavior for polling, local evaluation, caching, metrics, and shutdown.
Requirements
- Ruby 3.4 or later
Installation
Add the provider to your application’s Gemfile. The provider declares the OpenFeature SDK and the Unleash Ruby SDK as dependencies, so you don’t need to add them separately.
Then install your dependencies:
Configuration
Create an Unleash::OpenFeature::Provider::UnleashFlagProvider with the same options you would pass to the Unleash Ruby SDK client, then register it with OpenFeature.
Evaluate a flag
Build an OpenFeature client and evaluate flags through the OpenFeature API:
The provider supports all OpenFeature evaluation methods. Boolean evaluation uses the flag’s enabled state. All other types resolve from the payload of the flag’s variant:
- String values accept
stringandcsvpayloads. - Number, integer, and float values accept
numberpayloads. - Object values accept
jsonpayloads.
If the flag is disabled, or the variant payload is missing or has a different type, the evaluation returns the default value.
Context mapping
The provider maps the OpenFeature evaluation context to an Unleash context before each evaluation.
The following OpenFeature fields map directly to top-level Unleash context fields:
currentTimeuserIdsessionIdremoteAddressenvironmentappName
If you set targeting_key, the provider maps it to userId. The targeting_key takes precedence over a userId field set on the evaluation context.
The provider adds all other scalar fields, such as strings, numbers, booleans, and time values, to the Unleash context properties. It discards nested values, such as arrays and hashes.
Shutdown
Shut down the provider when your application exits. This also shuts down the underlying Unleash client.
Example
To try the provider against your Unleash instance, clone the provider repository and run the boolean flag example with your Unleash URL and API token: