Skip to main content

Flagsmith Ruby SDK

The SDK clients for Ruby https://flagsmith.com/. Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.

The source code for the client is available on Github.

Getting Started#

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See running in production for notes on how to deploy the project on a live system.

Installing#

VIA gem:

gem install flagsmith

Basic Usage#

The SDK is initialised against a single environment within a project on https://flagsmith.com, for example the Development or Production environment. You can find your environment key in the Environment settings page.

API Key

Usage#

Retrieving feature flags for your project#

require "flagsmith"
flagsmith = Flagsmith.new("<<Your API KEY>>")
if flagsmith.get_value("font_size")  #    Do something awesome with the font sizeend
if flagsmith.feature_enabled?("does_not_exist")  #do somethingelse  #do nothing, or something elseend

Available Options#

PropertyDescriptionRequiredDefault ValueEnvironment Key
api_keyDefines which project environment you wish to get flags for. example ACME Project - Staging.YESnullFLAGSMITH_API_KEY
urlUse this property to define where you're getting feature flags from, e.g. if you're self hosting.NOhttps://api.flagsmith.com/api/v1/FLAGSMITH_URL

Available Functions#

PropertyDescription
initInitialize the sdk against a particular environment
feature_enabled?(key)Get the value of a particular feature e.g. flagsmith.feature_enabled?("powerUserFeature") // true
feature_enabled?(key, user_id, default = false)Get the value of a particular feature for a user e.g. flagsmith.feature_enabled?("powerUserFeature", 1234) // true
get_value(key)Get the value of a particular feature e.g. flagsmith.get_value("font_size") // 10
get_value(key, user_id, default = nil)Get the value of a particular feature for a specified user e.g. flagsmith.get_value("font_size", 1234) // 15
get_flags()Trigger a manual fetch of the environment features, if a user is identified it will fetch their features
get_flags(user_id)Trigger a manual fetch of the environment features with a given user id
set_trait(user_id, trait, value)Set the value of a trait for the given user id

Identifying Users#

Identifying users allows you to target specific users from the Flagsmith dashboard. You can include an optional user identifier as part of the feature_enabled? and get_value methods to retrieve unique user flags and variables.