The following information is for the latest SDK version (6.x). The CloudBees platform requires that your installed SDK version be at least 6.x. Please install the latest SDK by following the instructions in the platform UI or in the SDK installation documentation. Any updates to version 6.x are noted in the platform changelog. |
type Rox
require 'rox/server/rox_server'
Rox::Server::RoxServer
The Rox
class provides an interface for CloudBees Feature Management to manage feature flags that control the behavior of your application.
This is the central repository for your application’s flags.
This class handles communications with the server to obtain the latest flag values, implement flag settings, and set up flag configurations.
It works with a RoxContainer
object, which holds your application’s feature flags.
The values in the provided container are marked as feature flags and display in the CloudBees Feature Management UI once the application is run.
This class also allows you to manage custom properties. These can be static settings of type string, Boolean, integer, or double, or use a generator type to provide a custom property that is dependent upon code state.
You can also use a RoxOptions
object to configure some aspects of this type.
Set the verbosity level, custom platform, global freeze level, impression handler, and fetch handler.
setup
Rox::Server::RoxServer.setup("<ROLLOUT_KEY>"[, Rox::Server::RoxOptions]).join
Configures the Rox
object to work with the provided application.
Parameter | Modifier and Type | Description |
---|---|---|
apiKey |
string |
The environment-specific SDK key provided by the CloudBees platform UI. |
options |
RoxOptions (optional) |
A |
Returns a thread that indicates when the SDK has received the configuration from the CloudBees platform.
shutdown
Rox::Server::RoxServer.shutdown
Performs graceful shutdown of the Rox
object to close and clean all background tasks and threads.
Shutdown
can only be used when Rox
has been successfully set up; otherwise it results in a log warning.
You can call Setup
again after Shutdown
.
In that case, register
and setCustomProperty
use the new Rox
object, and register the objects to the UI on the next setup
call.
register
Rox::Server::RoxServer.register(container)
Rox::Server::RoxServer.register_with_namespace(namespace, container)
Registers a feature flag container with the Rox
client.
The public member variables of this container are a flag in the platform UI and are named with the object name.
When using register
, the container does not use namespace
, so flag names do not have a prefix.
It is equivalent to register_with_namespace
with a namespace as an empty string.
Parameter | Modifier and type | Description |
---|---|---|
namespace |
string |
The prefix namespace for all flags in this container (defaults to |
container |
object |
An object that contains your application’s feature flags. |
The following example creates and registers a new container.
The flags in the UI have the names
login.include_facebook
, login.include_github
, showNewUserScreen
, and useBulkFetch
.
The namespace is useful for organizing flags.
set_custom_boolean_property
Rox::Server::RoxServer.set_custom_boolean_property(name, value = nil, &block)
Sets a custom Boolean property on the Rox
client.
The value can be either a Boolean or a computed Boolean.
Parameter | Modifier and type | Description |
---|---|---|
name |
value |
The name of the property to create. |
Boolean |
|
|
To create a new container and register it:
Rox::Server::RoxServer.set_custom_boolean_property('hasItemsInShoppingCart') do |context| context['shopping_cart'].empty? end
set_custom_string_property
Rox::Server::RoxServer.set_custom_string_property(name, value = nil, &block)
Sets a custom string property on the Rox
client.
The value can be either a string or a computed string.
Parameter | Modifier and type | Description |
---|---|---|
name |
value |
The name of the property to create. |
string |
|
|
To create a new container and register it:
Rox::Server::RoxServer.set_custom_string_property('email') do |context| context['user'].email end
set_custom_float_property
Rox::Server::RoxServer.set_custom_float_property(name, value = nil, &block)
Sets a custom float property on the Rox
client.
The value can be either a float or a computed float.
Parameter | Modifier and type | Description |
---|---|---|
name |
value |
The name of the property to create |
float |
|
|
To create a new container and register it:
Rox::Server::RoxServer.set_custom_float_property('height') do |context| context['user'].height end
set_custom_int_property
Rox::Server::RoxServer.set_custom_int_property(name, value = nil, &block)
Sets a custom int property on the Rox
client.
The value can be either an integer or a computed integer.
Parameter | Modifier and type | Description |
---|---|---|
name |
value |
The name of the property to create. |
int |
|
|
To create a new container and register it:
Rox::Server::RoxServer.set_custom_int_property('age') do |context| context['user'].age end
set_custom_semver_property
Rox::Server::RoxServer.set_custom_semver_property(name, value = nil, &block)
Sets a custom semver property on the Rox
client.
The value can be either a semver or a computed semver type.
Parameter | Modifier and type | Description |
---|---|---|
name |
value |
The name of the property to create |
string |
|
|
To create a new container and register it:
Rox::Server::RoxServer.set_custom_semver_property('ruby version', RUBY_VERSION)
Global context
Rox::Server::RoxServer.context
Sets a global context that is available to all flag evaluations.
global_context = {'user': user} Rox::Server::RoxServer.context = global_context
use_userspace_unhandled_error_handler
Rox::Server::RoxServer.use_userspace_unhandled_error_handler do |exception_source, exception_trigger, exception| # ... end
A handler for all user function errors to assist with debugging and understanding unexpected flag values. If not set, errors are logged to the logger.
CloudBees recommends wrapping all user methods with try-except to handle errors in the relevant context, rather than handling errors after.
|
When invoking the user_unhandled_error_invoker
, the arguments passed are the exception_source
, exception_trigger
and exception
.
The exception_source
is the original handler that caused the exception.
The exception_trigger
is an enum for the user to delegate the type:
class ExceptionTrigger DYNAMIC_PROPERTIES_RULE = 1 CONFIGURATION_FETCHED_HANDLER = 2 IMPRESSION_HANDLER = 3 CUSTOM_PROPERTY_GENERATOR = 4 end
The exception
is the exception that was originally raised.
type RoxOptions
Rox::Server::RoxOptions
RoxOptions
covers configuration options, including logging verbosity settings for the Rox
client.
Create instances of this type using server.NewRoxOptions
.
The following example sets up a new RoxOptions
object.
This object sets the version, creates a logger, provides an impression handler, and includes a configurationFetchedHandler.
require 'rox/server/rox_server' option = Rox::Server::RoxOptions.new( configuration_fetched_handler: configuration_fetched_handler, impression_handler: impression_handler, dynamic_property_rule_handler: dynamic_property_handler, logger: Logger.new, version: '2.0.0', fetch_interval: 120 ) Rox::Server::RoxServer.setup('<ROLLOUT_KEY>', option).join
fetch_interval
Sets the polling interval (in seconds) for fetching the configuration from the CloudBees platform storage service. The default is 60 seconds, and it cannot be set to below 30 seconds.
configuration_fetched_handler
Sets the configuration event handler, to add actions after configurations are fetched.
proc do |configuration_fetcher_args| # .. end
Properties of the argument, below, are passed into the configuration_fetched_handler
.
Property | Description |
---|---|
|
Enum indicating the fetch result; can be |
|
Date and time when the fetched configurations are created and signed. |
|
Enum indicating which error occurred while fetching and setting up new configurations.
Can be |
|
A Boolean indication (as opposed to a configuration change). |
impression_handler
Sets the impression event handler to add actions after an impression.
proc do |impression_handler_args| # .. end
Properties of the argument to be passed into the impression_handler
are detailed below.
Property | Description |
---|---|
|
Object that contains name (string), value (string), and targeting (boolean). |
|
The context in which the impression is called. This is a merged context containing the global context and the call’s context. |
dynamic_property_rule_handler
The dynamic custom property generator is called when an explicit custom property definition does not exist on the client side.
proc do |prop_name, context| # .. end
If you do not set the dynamic_property_rule_handler
, it activates the default method, which attempts to extract the property value from context.
Property | Description |
---|---|
|
The property name request by the flag evaluation. |
|
The context used to evaluate the flag. |
Refer to Properties, custom properties, and target groups for more information. |
type RoxFlag
require 'rox/server/flags/rox_flag'
Rox::Server::RoxFlag.new
RoxFlag
is a Boolean feature flag.
It can be either true or false.
Class RoxString
require 'rox/server/rox_server'
Rox::Server::RoxString.new
RoxString
is a feature flag object that can have string values.
RoxString
accepts a list of possible values for the feature flag and a default value.
Use this list when selecting new values for the feature, and you can override the value via the UI.
Class RoxInt
require 'rox/server/rox_int'
RoxInt
is a feature flag object that can have int values.
RoxInt
accepts a list of possible int values for the feature flag and a default value.
This list of values is used when selecting new values for the feature and is available for override in the UI.
title_size_flag = Rox::Server::RoxInt.new(14, [14, 18, 24]) title_size = title_size_flag.value
Class RoxDouble
require 'rox/server/rox_double'
RoxDouble
is a feature flag object that can have double values. RoxDouble
accepts a list of possible double values for the feature flag and a default value. This list of values is used when selecting new values for the feature and is available for override in the UI.