{"id":20607705,"url":"https://github.com/open-feature/ruby-sdk","last_synced_at":"2025-04-15T04:04:13.198Z","repository":{"id":64732517,"uuid":"487619032","full_name":"open-feature/ruby-sdk","owner":"open-feature","description":"Ruby implementation of the OpenFeature SDK","archived":false,"fork":false,"pushed_at":"2024-11-15T15:56:34.000Z","size":179,"stargazers_count":25,"open_issues_count":15,"forks_count":9,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-11-15T16:39:13.406Z","etag":null,"topics":["openfeature","ruby","sdk"],"latest_commit_sha":null,"homepage":"https://openfeature.dev","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-feature.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.MD","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-01T19:02:07.000Z","updated_at":"2024-11-15T15:56:38.000Z","dependencies_parsed_at":"2023-01-30T21:45:34.292Z","dependency_job_id":"3a0ba53c-2e99-4a64-bb2a-59f8c657998d","html_url":"https://github.com/open-feature/ruby-sdk","commit_stats":null,"previous_names":["open-feature/openfeature-ruby"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fruby-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fruby-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fruby-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fruby-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-feature","download_url":"https://codeload.github.com/open-feature/ruby-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224901313,"owners_count":17388950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openfeature","ruby","sdk"],"created_at":"2024-11-16T10:08:22.408Z","updated_at":"2024-11-16T10:08:23.125Z","avatar_url":"https://github.com/open-feature.png","language":"Ruby","readme":"\u003c!-- markdownlint-disable MD033 --\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/white/openfeature-horizontal-white.svg\" /\u003e\n    \u003cimg align=\"center\" alt=\"OpenFeature Logo\" src=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/black/openfeature-horizontal-black.svg\" /\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n\u003ch2 align=\"center\"\u003eOpenFeature Ruby SDK\u003c/h2\u003e\n\n\u003c!-- x-hide-in-docs-end --\u003e\n\u003c!-- The 'github-badges' class is used in the docs --\u003e\n\u003cp align=\"center\" class=\"github-badges\"\u003e\n  \u003ca href=\"https://github.com/open-feature/spec/releases/tag/v0.8.0\"\u003e\n    \u003cimg alt=\"Specification\" src=\"https://img.shields.io/static/v1?label=specification\u0026message=v0.8.0\u0026color=yellow\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- x-release-please-start-version --\u003e\n\n  \u003ca href=\"https://github.com/open-feature/ruby-sdk/releases/tag/v0.4.0\"\u003e\n    \u003cimg alt=\"Release\" src=\"https://img.shields.io/static/v1?label=release\u0026message=v0.4.0\u0026color=blue\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- x-release-please-end --\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://bestpractices.coreinfrastructure.org/projects/9337\"\u003e\n    \u003cimg alt=\"CII Best Practices\" src=\"https://bestpractices.coreinfrastructure.org/projects/9337/badge\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\n[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.\n\n\u003c!-- x-hide-in-docs-end --\u003e\n## 🚀 Quick start\n\n### Requirements\n\n| Supported Ruby Version | OS                    |\n| ------------ | --------------------- |\n| Ruby 3.1.4   | Windows, MacOS, Linux |\n| Ruby 3.2.3   | Windows, MacOS, Linux |\n| Ruby 3.3.0   | Windows, MacOS, Linux |\n\n### Install\n\nInstall the gem and add to the application's Gemfile by executing:\n\n```sh\nbundle add openfeature-sdk\n```\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n```sh\ngem install openfeature-sdk\n```\n\n### Usage\n\n```ruby\nrequire 'open_feature/sdk'\nrequire 'json' # For JSON.dump\n\n# API Initialization and configuration\n\nOpenFeature::SDK.configure do |config|\n  # your provider of choice, which will be used as the default provider\n  config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new(\n    {\n      \"flag1\" =\u003e true,\n      \"flag2\" =\u003e 1\n    }\n  ))\nend\n\n# Create a client\nclient = OpenFeature::SDK.build_client\n\n# fetching boolean value feature flag\nbool_value = client.fetch_boolean_value(flag_key: 'boolean_flag', default_value: false)\n\n# a details method is also available for more information about the flag evaluation\n# see `ResolutionDetails` for more info\nbool_details = client.fetch_boolean_details(flag_key: 'boolean_flag', default_value: false) ==\n\n# fetching string value feature flag\nstring_value = client.fetch_string_value(flag_key: 'string_flag', default_value: false)\n\n# fetching number value feature flag\nfloat_value = client.fetch_number_value(flag_key: 'number_value', default_value: 1.0)\ninteger_value = client.fetch_number_value(flag_key: 'number_value', default_value: 1)\n\n# get an object value\nobject = client.fetch_object_value(flag_key: 'object_value', default_value: JSON.dump({ name: 'object'}))\n```\n\n## 🌟 Features\n\n| Status | Features                                                            | Description                                                                                                                                                  |\n| ------ | --------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ✅      | [Providers](#providers)                                             | Integrate with a commercial, open source, or in-house feature management tool.                                                                               |\n| ✅      | [Targeting](#targeting)                                             | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context).                           |\n| ⚠️      | [Hooks](#hooks)                                                     | Add functionality to various stages of the flag evaluation life-cycle.                                                                                       |\n| ❌      | [Logging](#logging)                                                 | Integrate with popular logging packages.                                                                                                                     |\n| ✅      | [Domains](#domains)                                                 | Logically bind clients with providers.                                                                                                                       |\n| ❌      | [Eventing](#eventing)                                               | React to state changes in the provider or flag management system.                                                                                            |\n| ⚠️      | [Shutdown](#shutdown)                                               | Gracefully clean up a provider during application shutdown.                                                                                                  |\n| ❌      | [Transaction Context Propagation](#transaction-context-propagation) | Set a specific [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context) for a transaction (e.g. an HTTP request or a thread) |\n| ⚠️      | [Extending](#extending)                                             | Extend OpenFeature with custom providers and hooks.                                                                                                          |\n\n\u003csub\u003eImplemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌\u003c/sub\u003e\n\n### Providers\n\n[Providers](https://openfeature.dev/docs/reference/concepts/provider) are an abstraction between a flag management system and the OpenFeature SDK.\nLook [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Ruby) for a complete list of available providers.\nIf the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself.\n\nOnce you've added a provider as a dependency, it can be registered with OpenFeature like this:\n\n```ruby\nOpenFeature::SDK.configure do |config|\n  # your provider of choice, which will be used as the default provider\n  config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new(\n    {\n      \"v2_enabled\" =\u003e true,\n    }\n  ))\nend\n```\n\nIn some situations, it may be beneficial to register multiple providers in the same application.\nThis is possible using [domains](#domains), which is covered in more detail below.\n\n### Targeting\n\nSometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location.\nIn OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).\nIf the flag management system you're using supports targeting, you can provide the input data using the [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context).\n\n```ruby\nOpenFeature::SDK.configure do |config|\n  # you can set a global evaluation context here\n  config.evaluation_context = OpenFeature::SDK::EvaluationContext.new(\"host\" =\u003e \"myhost.com\")\nend\n\n# Evaluation context can be set on a client as well\nclient_with_context = OpenFeature::SDK.build_client(\n  evaluation_context: OpenFeature::SDK::EvaluationContext.new(\"controller_name\" =\u003e \"admin\")\n)\n\n# Invocation evaluation context can also be passed in during flag evaluation.\n# During flag evaluation, invocation context takes precedence over client context\n# which takes precedence over API (aka global) context.\nbool_value = client.fetch_boolean_value(\n  flag_key: 'boolean_flag',\n  default_value: false,\n  evaluation_context: OpenFeature::SDK::EvaluationContext.new(\"is_friday\" =\u003e true)\n)\n```\n\n### Hooks\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/52) to be worked on.\n\n\u003c!-- [Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle.\nLook [here](https://openfeature.dev/ecosystem/?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Hook\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Ruby) for a complete list of available hooks.\nIf the hook you're looking for hasn't been created yet, see the [develop a hook](#develop-a-hook) section to learn how to build it yourself.\n\nOnce you've added a hook as a dependency, it can be registered at the global, client, or flag invocation level. --\u003e\n\n\u003c!-- TODO: code example of setting hooks at all levels --\u003e\n\n### Logging\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/148) to work on.\n\n\u003c!-- TODO: talk about logging config and include a code example --\u003e\n\n### Domains\n\nClients can be assigned to a domain. A domain is a logical identifier which can be used to associate clients with a particular provider.\nIf a domain has no associated provider, the default provider is used.\n\n```ruby\nOpenFeature::SDK.configure do |config|\n  config.set_provider(OpenFeature::SDK::Provider::NoOpProvider.new, domain: \"legacy_flags\")\nend\n\n# Create a client for a different domain, this will use the provider assigned to that domain\nlegacy_flag_client = OpenFeature::SDK.build_client(domain: \"legacy_flags\")\n```\n\n### Eventing\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/51) to be worked on.\n\n\u003c!-- Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.\nInitialization events (`PROVIDER_READY` on success, `PROVIDER_ERROR` on failure) are dispatched for every provider.\nSome providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGED`.\n\nPlease refer to the documentation of the provider you're using to see what events are supported. --\u003e\n\n\u003c!-- TODO: code example of a PROVIDER_CONFIGURATION_CHANGED event for the client and a PROVIDER_STALE event for the API --\u003e\n\n### Shutdown\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/149) to be worked on.\n\n\u003c!-- TODO The OpenFeature API provides a close function to perform a cleanup of all registered providers.\nThis should only be called when your application is in the process of shutting down.\n\n```ruby\nclass MyProvider\n  def shutdown\n    # Perform any shutdown/reclamation steps with flag management system here\n    # Return value is ignored\n  end\nend\n``` --\u003e\n\n### Transaction Context Propagation\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/150) to be worked on.\n\n\u003c!-- Transaction context is a container for transaction-specific evaluation context (e.g. user id, user agent, IP).\nTransaction context can be set where specific data is available (e.g. an auth service or request handler) and by using the transaction context propagator it will automatically be applied to all flag evaluations within a transaction (e.g. a request or thread). --\u003e\n\n\u003c!-- TODO: code example for global shutdown --\u003e\n\n## Extending\n\n### Develop a provider\n\nTo develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency.\nThis can be a new repository or included in [the existing contrib repository](https://github.com/open-feature/ruby-sdk-contrib) available under the OpenFeature organization.\nYou’ll then need to write the provider by implementing the `Provider` duck.\n\n```ruby\nclass MyProvider\n  def init\n    # Perform any initialization steps with flag management system here\n    # Return value is ignored\n    # **Note** The OpenFeature spec defines a lifecycle method called `initialize` to be called when a new provider is set.\n    # To avoid conflicting with the Ruby `initialize` method, this method should be named `init` when creating a provider.\n  end\n\n  def shutdown\n    # Perform any shutdown/reclamation steps with flag management system here\n    # Return value is ignored\n  end\n\n  def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a boolean value from provider source\n  end\n\n  def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a string value from provider source\n  end\n\n  def fetch_number_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a numeric value from provider source\n  end\n\n  def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a integer value from provider source\n  end\n\n  def fetch_float_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a float value from provider source\n  end\n\n  def fetch_object_value(flag_key:, default_value:, evaluation_context: nil)\n    # Retrieve a hash value from provider source\n  end\nend\n```\n\n\u003e Built a new provider? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=provider\u0026projects=\u0026template=document-provider.yaml\u0026title=%5BProvider%5D%3A+) so we can add it to the docs!\n\n### Develop a hook\n\nComing Soon! [Issue available](https://github.com/open-feature/ruby-sdk/issues/52) to be worked on.\n\n\u003c!-- To develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency.\nThis can be a new repository or included in [the existing contrib repository](https://github.com/open-feature/ruby-sdk-contrib) available under the OpenFeature organization.\nImplement your own hook by conforming to the `Hook interface`.\nTo satisfy the interface, all methods (`Before`/`After`/`Finally`/`Error`) need to be defined.\nTo avoid defining empty functions, make use of the `UnimplementedHook` struct (which already implements all the empty functions). --\u003e\n\n\u003c!-- TODO: code example of hook implementation --\u003e\n\n\u003c!-- \u003e Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=hook\u0026projects=\u0026template=document-hook.yaml\u0026title=%5BHook%5D%3A+) so we can add it to the docs! --\u003e\n\n\u003c!-- x-hide-in-docs-start --\u003e\n## ⭐️ Support the project\n\n- Give this repo a ⭐️!\n- Follow us on social media:\n  - Twitter: [@openfeature](https://twitter.com/openfeature)\n  - LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)\n- Join us on [Slack](https://cloud-native.slack.com/archives/C0344AANLA1)\n- For more, check out our [community page](https://openfeature.dev/community/)\n\n## 🤝 Contributing\n\nInterested in contributing? Great, we'd love your help! To get started, take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.\n\n### Thanks to everyone who has already contributed\n\n\u003ca href=\"https://github.com/open-feature/ruby-sdk/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=open-feature/ruby-sdk\" alt=\"Pictures of the folks who have contributed to the project\" /\u003e\n\u003c/a\u003e\n\n\nMade with [contrib.rocks](https://contrib.rocks).\n\u003c!-- x-hide-in-docs-end --\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fruby-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-feature%2Fruby-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fruby-sdk/lists"}