Unleash OpenFeature Ruby Provider

The official Unleash OpenFeature provider for Ruby.

Requirements

  • Ruby 3.4+
  • Bundler

Install

gem 'unleash-openfeature-provider'

For local development:

bundle install

If you cloned without submodules, initialize the verifier harness:

git submodule update --init --recursive

Use

require 'open_feature/sdk'
require 'unleash'
require 'unleash-openfeature-provider'

unleash_client = Unleash::Client.new(
  app_name: 'my-ruby-app',
  url: 'https://app.unleash-hosted.com/demo/api',
  custom_http_headers: {
    Authorization: '<client-api-key>'
  }
)

OpenFeature::SDK.configure do |config|
  config.set_provider(Unleash::OpenFeature::Provider::UnleashFlagProvider.new(unleash_client))
end

client = OpenFeature::SDK.build_client
enabled = client.fetch_boolean_value(
  flag_key: 'my-feature',
  default_value: false,
  evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: 'user-123')
)

Example

bundle exec ruby examples/boolean_flag.rb \
  --url https://app.unleash-hosted.com/demo/api \
  --api-key "$UNLEASH_API_KEY" \
  --flag-key my-feature \
  --targeting-key user-123

Build

bundle exec rake build

Build artifacts are written to pkg/.

Test

bundle exec rspec

The contract tests use the verifier submodule. To refresh it:

git submodule update --remote --merge verifier

Lint

bundle exec rubocop