Skip to content

feat: Add Flipt provider gem with basic implementation #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,26 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
working-directory: ./providers/openfeature-go-feature-flag-provider
- name: Lint and test
run: bin/rake
run: bin/rake

test_flipt_provider:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./providers/openfeature-flipt-provider
strategy:
matrix:
ruby-version:
- "3.3"
- "3.2"
- "3.1"
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
working-directory: ./providers/openfeature-flipt-provider
- name: Lint and test
run: bin/rake
11 changes: 11 additions & 0 deletions providers/openfeature-flipt-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
4 changes: 4 additions & 0 deletions providers/openfeature-flipt-provider/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-I lib
--format documentation
--color
--require spec_helper
5 changes: 5 additions & 0 deletions providers/openfeature-flipt-provider/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inherit_from: ../../shared_config/.rubocop.yml

inherit_mode:
merge:
- Exclude
1 change: 1 addition & 0 deletions providers/openfeature-flipt-provider/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.5
Empty file.
6 changes: 6 additions & 0 deletions providers/openfeature-flipt-provider/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in openfeature-flipt-provider.gemspec
gemspec
108 changes: 108 additions & 0 deletions providers/openfeature-flipt-provider/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
PATH
remote: .
specs:
openfeature-flipt-provider (0.1.0)
ffi (~> 1.17)
flipt_client (~> 0.10.0)
openfeature-sdk (~> 0.4.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
diff-lcs (1.6.1)
ffi (1.17.1)
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-arm-linux-gnu)
ffi (1.17.1-arm-linux-musl)
ffi (1.17.1-arm64-darwin)
ffi (1.17.1-x86-linux-gnu)
ffi (1.17.1-x86-linux-musl)
ffi (1.17.1-x86_64-darwin)
ffi (1.17.1-x86_64-linux-gnu)
ffi (1.17.1-x86_64-linux-musl)
flipt_client (0.10.0)
json (2.10.2)
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
openfeature-sdk (0.4.0)
parallel (1.26.3)
parser (3.3.7.3)
ast (~> 2.4.1)
racc
prism (1.4.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.10.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.3)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.7)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.2)
rubocop (1.73.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.43.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-performance (1.24.0)
lint_roller (~> 1.1)
rubocop (>= 1.72.1, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (1.13.0)
standard (1.47.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.73.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.7)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.7.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.24.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
aarch64-linux-gnu
aarch64-linux-musl
arm-linux-gnu
arm-linux-musl
arm64-darwin
ruby
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
openfeature-flipt-provider!
rake (~> 13.0)
rspec (~> 3.12.0)
rubocop
standard (>= 1.35.1)

BUNDLED WITH
2.5.16
57 changes: 57 additions & 0 deletions providers/openfeature-flipt-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<p align="center">
<img width="400" src="https://raw.githubusercontent.com/flipt-io/flipt/main/logo.svg" alt="flipt logo" />
</p>

# Flipt - OpenFeature Ruby provider

This repository contains the Ruby provider for [Flipt](https://www.flipt.io/), a feature flagging and experimentation platform.

In conjunction with the [OpenFeature SDK](https://openfeature.dev/docs/reference/concepts/provider/) you can use this provider to integrate Flipt into your Ruby application.

For documentation on how to use Flipt, please refer to the [Flipt documentation](https://docs.flipt.io/).

## Installation
Add this line to your application's Gemfile:

```ruby
gem 'openfeature-flipt-provider'
```

And then execute:
```bash
$ bundle
```

## Usage
To use the Flipt provider, you need to create an instance of the provider and pass it to the OpenFeature SDK.

```ruby
require "open_feature/sdk"
require "openfeature/flipt/provider"

OpenFeature::SDK.configure do |config|
config.set_provider(
OpenFeature::Flipt::Provider.new(
namespace: "flipt-namespace",
options: {
url: "https://url-to-flipt-server",
update_interval: 60,
authentication: "token"
}
)
)
end
client = OpenFeature::SDK.build_client

# Check if a feature is enabled
if client.fetch_boolean_value(flag_key: "featureEnabled", default_value: false)
puts "Feature is enabled"
else
puts "Feature is disabled"
end
```

For a complete list of configuration options, such as authentication and error strategies, refer to the [Flipt Client Ruby SDK documentation](https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-client-ruby#constructor-arguments).

## Contributing
https://github.com/open-feature/ruby-sdk-contrib
10 changes: 10 additions & 0 deletions providers/openfeature-flipt-provider/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require "standard/rake"

task default: %i[standard spec]
11 changes: 11 additions & 0 deletions providers/openfeature-flipt-provider/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "openfeature/flipt/provider"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
27 changes: 27 additions & 0 deletions providers/openfeature-flipt-provider/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
8 changes: 8 additions & 0 deletions providers/openfeature-flipt-provider/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
Loading
Loading