Ruby SDK installation

2 minute read

Control feature rollout for certain user segments of your application with feature flags. To start using feature management in the platform, follow the instructions below to install the SDK and deploy a feature flag.

Install the SDK

Follow these steps to install the SDK:

  1. Select Feature management  Installation.

  2. Select an Environment from the options, or create an environment by completing the following:

    1. Select Create environment.

    2. Enter an Environment name.

    3. (Optional) Enter a Description.

    4. (Optional) Select Approvers if you want to have a manual approval required before deployment.

    5. (Optional) Enter any Properties you want to associate with the environment. For more information, refer to properties configuration and properties in an environment.

    6. Select Submit.

  3. Select Ruby as the language.

  4. Choose a package manager (for example, RubyGems or Bundler).

  5. To install the SDK, run the following command:

    gem install rox-rollout

    or, if using Bundler, add this to your Gemfile:

    gem 'rox-rollout', '~> 6.0'

    Then install it using:

    bundle install

Add feature flags to your Ruby application

Follow these steps to configure feature flags using the SDK:

  1. Import the SDK into your application.

  2. Create a feature flag container.

  3. Register the container with CloudBees feature management.

  4. Set up the SDK with your environment key.

    For example, use this code to add feature flags:

    # Import the SDK require 'rox/server/rox_server' # Define a feature flag container class FeatureFlags attr_accessor :enable_tutorial, :title_color, :page, :percentage def initialize # Define the feature flags @enable_tutorial = Rox::Server::RoxFlag.new @title_color = Rox::Server::RoxString.new('White', ['White', 'Blue', 'Green', 'Yellow']) @page = Rox::Server::RoxInt.new(1, [1, 2, 3]) @percentage = Rox::Server::RoxDouble.new(99.9, [10.5, 50.0, 99.9]) end end # Initialize the feature flag container flags = FeatureFlags.new # Register the container with Rox Rox::Server::RoxServer.register('default', flags) # Set up the SDK with your environment key (Replace <YOUR-SDK-KEY> with the actual key) Rox::Server::RoxServer.setup('<YOUR-SDK-KEY>').join(1) # Example usage puts "Feature flag 'enable_tutorial' is #{flags.enable_tutorial.enabled?}" puts "Selected title color: #{flags.title_color.value}" puts "Selected page: #{flags.page.value}" puts "Selected percentage: #{flags.percentage.value}"
    1 The CloudBees platform provides the unique SDK key for your environment at the '<YOUR-SDK-KEY>' location inside the Rox::Server::RoxServer.setup call. Additionally, the .join method blocks the main thread. If that is not required, use .setup('<YOUR-SDK-KEY>') instead.

Run your application and test the integration

Follow these steps to verify that the SDK integration is working:

  1. Run your application.

    ruby my_app.rb
  2. Select Test integration.

    This verifies that the SDK is properly communicating with the CloudBees feature management service.

  3. Check for flags in the Feature management dashboard.

    After running your application for the first time, any feature flags added in the code will automatically appear in the Feature management dashboard.