Class: LaunchDarkly::Integrations::TestData::FlagBuilder
- Inherits:
-
Object
- Object
- LaunchDarkly::Integrations::TestData::FlagBuilder
- Defined in:
- lib/ldclient-rb/integrations/test_data/flag_builder.rb
Overview
A builder for feature flag configurations to be used with LaunchDarkly::Integrations::TestData.
Defined Under Namespace
Classes: FlagMigrationSettingsBuilder, FlagRuleBuilder
Instance Attribute Summary collapse
- #key ⇒ Object readonly
Instance Method Summary collapse
-
#boolean_flag ⇒ FlagBuilder
A shortcut for setting the flag to use the standard boolean configuration.
-
#clear_rules ⇒ FlagBuilder
Removes any existing rules from the flag.
-
#clear_targets ⇒ FlagBuilder
Removes any existing targets from the flag.
-
#exclude_from_summaries(exclude) ⇒ FlagBuilder
Set the option to exclude this flag from summary events.
-
#fallthrough_variation(variation) ⇒ FlagBuilder
Specifies the fallthrough variation.
-
#if_match(attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is one of" operator.
-
#if_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is one of" operator.
-
#if_not_match(attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is not one of" operator.
-
#if_not_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is not one of" operator.
-
#migration_settings(settings) ⇒ FlagBuilder
Set the migration related settings for this feature flag.
-
#off_variation(variation) ⇒ FlagBuilder
Specifies the off variation for a flag.
-
#on(on) ⇒ FlagBuilder
Sets targeting to be on or off for this flag.
-
#sampling_ratio(ratio) ⇒ FlagBuilder
Set the sampling ratio for this flag.
-
#value_for_all(value) ⇒ FlagBuilder
Sets the flag to always return the specified variation value for all context.
-
#variation_for_all(variation) ⇒ FlagBuilder
Sets the flag to always return the specified variation for all contexts.
-
#variation_for_key(context_kind, context_key, variation) ⇒ FlagBuilder
Sets the flag to return the specified variation for a specific context key when targeting is on.
-
#variation_for_user(user_key, variation) ⇒ FlagBuilder
Sets the flag to return the specified variation for a specific user key when targeting is on.
-
#variations(*variations) ⇒ FlagBuilder
Changes the allowable variation values for the flag.
Instance Attribute Details
#key ⇒ Object (readonly)
13 14 15 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 13 def key @key end |
Instance Method Details
#boolean_flag ⇒ FlagBuilder
A shortcut for setting the flag to use the standard boolean configuration.
This is the default for all new flags created with LaunchDarkly::Integrations::TestData#flag.
The flag will have two variations, true
and false
(in that order);
it will return false
whenever targeting is off, and true
when targeting is on
if no other settings specify otherwise.
379 380 381 382 383 384 385 386 387 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 379 def boolean_flag if boolean_flag? self else variations(true, false) .fallthrough_variation(TRUE_VARIATION_INDEX) .off_variation(FALSE_VARIATION_INDEX) end end |
#clear_rules ⇒ FlagBuilder
Removes any existing rules from the flag. This undoes the effect of methods like #if_match
355 356 357 358 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 355 def clear_rules @rules = nil self end |
#clear_targets ⇒ FlagBuilder
Removes any existing targets from the flag. This undoes the effect of methods like #variation_for_key
344 345 346 347 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 344 def clear_targets @targets = nil self end |
#exclude_from_summaries(exclude) ⇒ FlagBuilder
Set the option to exclude this flag from summary events. This is used to control the size of the summary event in the event certain flag payloads are large.
General usage should not require interacting with this method.
82 83 84 85 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 82 def exclude_from_summaries(exclude) @exclude_from_summaries = exclude self end |
#fallthrough_variation(variation) ⇒ FlagBuilder
Specifies the fallthrough variation. The fallthrough is the value that is returned if targeting is on and the context was not matched by a more specific target or rule.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
99 100 101 102 103 104 105 106 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 99 def fallthrough_variation(variation) if LaunchDarkly::Impl::Util.bool? variation boolean_flag.fallthrough_variation(variation_for_boolean(variation)) else @fallthrough_variation = variation self end end |
#if_match(attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is one of" operator.
This is a shortcut for calling #if_match_context with
LaunchDarkly::LDContext::KIND_DEFAULT
as the context kind.
290 291 292 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 290 def if_match(attribute, *values) if_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) end |
#if_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is one of" operator.
267 268 269 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 267 def if_match_context(context_kind, attribute, *values) FlagRuleBuilder.new(self).and_match_context(context_kind, attribute, *values) end |
#if_not_match(attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is not one of" operator.
This is a shortcut for calling #if_not_match_context with
LaunchDarkly::LDContext::KIND_DEFAULT
as the context kind.
334 335 336 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 334 def if_not_match(attribute, *values) if_not_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) end |
#if_not_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Starts defining a flag rule, using the "is not one of" operator.
311 312 313 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 311 def if_not_match_context(context_kind, attribute, *values) FlagRuleBuilder.new(self).and_not_match_context(context_kind, attribute, *values) end |
#migration_settings(settings) ⇒ FlagBuilder
Set the migration related settings for this feature flag.
The settings hash should be built using the FlagMigrationSettingsBuilder.
54 55 56 57 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 54 def migration_settings(settings) @migration_settings = settings self end |
#off_variation(variation) ⇒ FlagBuilder
Specifies the off variation for a flag. This is the variation that is returned whenever targeting is off.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
119 120 121 122 123 124 125 126 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 119 def off_variation(variation) if LaunchDarkly::Impl::Util.bool? variation boolean_flag.off_variation(variation_for_boolean(variation)) else @off_variation = variation self end end |
#on(on) ⇒ FlagBuilder
Sets targeting to be on or off for this flag.
The effect of this depends on the rest of the flag configuration, just as it does on the
real LaunchDarkly dashboard. In the default configuration that you get from calling
LaunchDarkly::Integrations::TestData#flag with a new flag key, the flag will return false
whenever targeting is off, and true
when targeting is on.
41 42 43 44 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 41 def on(on) @on = on self end |
#sampling_ratio(ratio) ⇒ FlagBuilder
Set the sampling ratio for this flag. This ratio is used to control the emission rate of feature, debug, and migration op events.
General usage should not require interacting with this method.
68 69 70 71 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 68 def sampling_ratio(ratio) @sampling_ratio = ratio self end |
#value_for_all(value) ⇒ FlagBuilder
Sets the flag to always return the specified variation value for all context.
The value may be of any valid JSON type. This method changes the flag to have only a single variation, which is this value, and to return the same variation regardless of whether targeting is on or off. Any existing targets or rules are removed.
183 184 185 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 183 def value_for_all(value) variations(value).variation_for_all(0) end |
#variation_for_all(variation) ⇒ FlagBuilder
Sets the flag to always return the specified variation for all contexts.
The variation is specified, Targeting is switched on, and any existing targets or rules are removed. The fallthrough variation is set to the specified value. The off variation is left unchanged.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
164 165 166 167 168 169 170 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 164 def variation_for_all(variation) if LaunchDarkly::Impl::Util.bool? variation boolean_flag.variation_for_all(variation_for_boolean(variation)) else on(true).clear_rules.clear_targets.fallthrough_variation(variation) end end |
#variation_for_key(context_kind, context_key, variation) ⇒ FlagBuilder
Sets the flag to return the specified variation for a specific context key when targeting is on.
This has no effect when targeting is turned off for the flag.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 202 def variation_for_key(context_kind, context_key, variation) if LaunchDarkly::Impl::Util.bool? variation return boolean_flag.variation_for_key(context_kind, context_key, variation_for_boolean(variation)) end if @targets.nil? @targets = Hash.new end targets = @targets[context_kind] || [] @variations.count.times do | i | if i == variation if targets[i].nil? targets[i] = [context_key] else targets[i].push(context_key) end elsif not targets[i].nil? targets[i].delete(context_key) end end @targets[context_kind] = targets self end |
#variation_for_user(user_key, variation) ⇒ FlagBuilder
Sets the flag to return the specified variation for a specific user key when targeting is on.
This is a shortcut for calling #variation_for_key with
LaunchDarkly::LDContext::KIND_DEFAULT
as the context kind.
This has no effect when targeting is turned off for the flag.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
246 247 248 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 246 def variation_for_user(user_key, variation) variation_for_key(LaunchDarkly::LDContext::KIND_DEFAULT, user_key, variation) end |
#variations(*variations) ⇒ FlagBuilder
Changes the allowable variation values for the flag.
The value may be of any valid JSON type. For instance, a boolean flag
normally has true, false
; a string-valued flag might have
'red', 'green'
; etc.
146 147 148 149 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 146 def variations(*variations) @variations = variations self end |