Boolean flags, which can only be configured to true or false, are central to CloudBees Feature Management. The default flag value, which is the flag value when configuration is disabled, is the value specified in the code. If no value is specified in your code, the default boolean flag value is false. If configuration is enabled, the boolean flag value can be set in the UI. To learn more, refer to Setting the flag default values.
The boolean flag name is derived from the flag variable name.
Creating a boolean flag in the UI
To create a boolean flag in the UI, select the Boolean flag type when you create your flag. Refer to Creating feature flags for more information.
Creating a container class and defining a feature flag
You can create boolean flags in your code using the static API. A container class is required, and you define your flag inside the container class.
In the following examples, a container class and a boolean flag are defined. The flag name, videoChat, is derived from the flag variable name. This flag is false by default.
import Foundation import ROX public class Flags: RoxContainer{ public let videoChat = RoxFlag(); }
#import <ROXCore/ROXCore.h> @interface Flags : ROXBaseContainer @property (nonatomic) ROXFlag* videoChat; @end #import "Flags.h" @implementation Flags - (instancetype)init { self = [super init]; if (self) { self.videoChat = [[ROXFlag alloc] init]; } return self; } @end
const flags = { videoChat: new Rox.Flag() };
const flags = { videoChat: new Rox.Flag() };
const flags = { videoChat: new Rox.Flag() };
import {Flag} from 'rox-ssr'; const flags = { videoChat: new Flag() };
public class Flags implements RoxContainer{ public RoxFlag videoChat = new RoxFlag(); }
public class Flags implements RoxContainer{ public RoxFlag videoChat = new RoxFlag(); }
import kotlin.jvm.JvmField class Flags: RoxContainer { @JvmField val videoChat = RoxFlag() }
public class Flags : IRoxContainer { public RoxFlag videoChat = new RoxFlag(); }
from rox.server.flags.rox_flag import RoxFlag class MyContainer: def __init__(self): self.video_chat = RoxFlag()
import ( "github.com/rollout/rox-go/v5/server" ) type Container struct { EnableTutorial server.RoxFlag } var flags = &Container { // Default value must be specified with go EnableTutorial: server.NewRoxFlag(false), }
require 'rox/server/rox_server' class Container attr_accessor :video_chat def initialize @video_chat = Rox::Server::RoxFlag.new end end
use Rox\Server\Rox; use Rox\Server\Flags\RoxFlag; require __DIR__ . '/vendor/autoload.php'; class Container { public $videoChat; public function __construct() { $this->videoChat = new RoxFlag(false); } }
RoxStringBase *videoChat = rox_add_flag("demo.video_chat", false);
RoxStringBase *videoChat = rox_add_flag_with_freeze("demo.video_chat", false, RoxFreezeUntilLaunch);
auto videoChat = Rox::Flag::Create("demo.video_chat", false);
auto videoChat = Rox::Client::Flag::Create("demo.video_chat", false, RoxFreezeUntilLaunch);
Registering the container class
To use the container class, register its instance to the CloudBees Feature Management SDK with the Rox.register()
SDK function.
The namespace parameter is a logical separation between containers, and can be used to find flags on the dashboard.
A namespace can only be registered once. |
In the following examples, the Rox.register()
SDK function is called to
register the class instance:
const flags = { // define Rox entities here } Rox.register('<namespace>', flags); await Rox.setup('<YOUR_APP_KEY>');
const flags = { // define Rox entities here } Rox.register('<namespace>', flags); Rox.setup('<YOUR_APP_KEY>');
const flags = { // define Rox entities here } Rox.register('<namespace>', flags); await Rox.setup('<YOUR_APP_KEY>');
import {Rox} from 'rox-ssr'; const flags = { // define Rox entities here } Rox.register('<namespace>', flags); Rox.setup('<YOUR_APP_KEY>');
public class App extends Application { @Override public void onCreate() { super.onCreate(); Flags flags = new Flags(); Rox.register("<namespace>", flags); Rox.setup(this); // This can also be set up in MainActivity if your app doesn't extend the Application class } }
Flags flags = new Flags(); Rox.register("<namespace>", flags); Rox.setup(YOUR_APP_KEY);
Container flags = new Container(); Rox.Register("<namespace>", flags); await Rox.Setup(<YOUR_APP_KEY>);
from rox.server.rox_server import Rox flags = MyContainer() Rox.register(<namespace>, flags) cancel_event = Rox.setup('<YOUR_APP_KEY>').result()
package main import "github.com/rollout/rox-go/v5/server" type Container struct { EnableTutorial server.RoxFlag } var flags = &Container { // Default value must be specified with go EnableTutorial: server.NewRoxFlag(false), } var rox *server.Rox func main() { options := server.NewRoxOptions(server.RoxOptionsBuilder {}) rox = server.NewRox() rox.Register("<namespace>", flags) <-rox.Setup("<YOUR_APP_KEY>", options) }
require 'rox/server/rox_server' class Container end flags = Container.new Rox::Server::RoxServer.register(<namespace>, flags) Rox::Server::RoxServer.setup(<YOUR_APP_KEY>).join
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { ROX.register("<namespace>", container: Flags()) ROX.setup(withKey: YOUR_APP_KEY) return true }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [ROX register:[[Flags alloc] init]]; [ROX setupWithKey:@<YOUR_APP_KEY>]; return YES; }
use Rox\Server\Flags\RoxFlag; use Rox\Server\Rox; class Container { public $videoChat; public function __construct() { $this->videoChat = new RoxFlag(); } } $container = new Container(); Rox::register(<namespace>, $container); Rox::setup(<YOUR_APP_KEY>);
#include <rox/server.h> #define DEFAULT_API_KEY "YOUR_APP_KEY" int main(int argc, char **argv) { RoxStringBase *videoChat = rox_add_flag("demo.video_chat", false); rox_setup(DEFAULT_API_KEY, NULL); rox_shutdown(); }
#include <rox/client.h> #define DEFAULT_API_KEY "YOUR_APP_KEY" int main(int argc, char **argv) { RoxStringBase *videoChat = rox_add_flag_with_freeze("demo.video_chat", false, RoxFreezeUntilLaunch); rox_setup(DEFAULT_API_KEY, NULL); rox_shutdown(); }
#include <roxx/server.h> #define DEFAULT_API_KEY "YOUR_APP_KEY" using namespace Rox; int main(int argc, char **argv) { auto videoChat = Rox::Flag::Create("demo.video_chat", false); Rox::Setup(DEFAULT_API_KEY, NULL); Rox::Shutdown(); }
#include <roxx/client.h> #define DEFAULT_API_KEY "YOUR_APP_KEY" using namespace Rox::Client; int main(int argc, char **argv) { auto videoChat = Rox::Client::Flag::Create("demo.video_chat", false, RoxFreezeUntilLaunch); Rox::Setup(DEFAULT_API_KEY, NULL); Rox::Shutdown(); }
Using a boolean flag
The following examples check the flag value:
if (flags.videoChat.isEnabled()) { console.log('videoChat is enabled'); }
if (flags.videoChat.isEnabled()) { console.log('videoChat is enabled'); }
if (flags.videoChat.isEnabled()) { console.log('videoChat is enabled'); }
if (flags.videoChat.isEnabled()) { console.log('videoChat is enabled'); }
if (flags.videoChat.isEnabled()) { Log.i(tag, "VideoChat Feature is Enabled"); }
if (flags.videoChat.isEnabled()) { Logger.info(tag, "VideoChat Feature is Enabled"); }
if (flags.videoChat.isEnabled() == true) { // videoChat is enabled }
if my_container.video_chat.is_enabled(): print('video_chat is enabled')
if (flags.VideoChat.IsEnabled(nil)) { // ... }
if container.video_chat.enabled? puts "video_chat is enabled" end
flags.videoChat.enabled { print("VideoChat Feature is Enabled") }
[myContainer.videoChat enabled:^{ NSLog(@"VideoChat Feature is Enabled"); } disabled:^{ // ... }];
if ($container->videoChat->isEnabled()) { echo 'video chat is enabled'; }
if (rox_is_enabled(videoChat)) { // ... }
if (videoChat->IsEnabled()) { // ... }
Default flag values
A boolean flag is false by default. To override the value, pass true to the flag.
Flag freeze is available on client-side SDKs by default.
Refer to Understanding a flag freeze for more information. |