Class: LaunchDarkly::Integrations::TestData::FlagBuilder::FlagRuleBuilder
- Inherits:
-
Object
- Object
- LaunchDarkly::Integrations::TestData::FlagBuilder::FlagRuleBuilder
- Defined in:
- lib/ldclient-rb/integrations/test_data/flag_builder.rb
Overview
A builder for feature flag rules to be used with LaunchDarkly::Integrations::TestData::FlagBuilder.
In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as “name is ‘X’”. A rule matches a context if all of the rule’s clauses match the context.
To start defining a rule, use one of the flag builder’s matching methods such as #if_match. This defines the first clause for the rule. Optionally, you may add more clauses with the rule builder’s methods such as #and_match or #and_not_match. Finally, call #then_return to finish defining the rule.
Defined Under Namespace
Classes: FlagRuleClause
Instance Method Summary collapse
-
#and_match(attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is one of” operator.
-
#and_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is one of” operator.
-
#and_not_match(attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is not one of” operator.
-
#and_not_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is not one of” operator.
- #build(ri) ⇒ Object
-
#initialize(flag_builder) ⇒ FlagRuleBuilder
constructor
A new instance of FlagRuleBuilder.
- #intialize_copy(other) ⇒ Object
-
#then_return(variation) ⇒ FlagBuilder
Finishes defining the rule, specifying the result as either a boolean or a variation index.
Constructor Details
#initialize(flag_builder) ⇒ FlagRuleBuilder
Returns a new instance of FlagRuleBuilder.
493 494 495 496 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 493 def initialize(flag_builder) @flag_builder = flag_builder @clauses = Array.new end |
Instance Method Details
#and_match(attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is one of” operator.
This is a shortcut for calling #and_match_context with ‘LaunchDarkly::LDContext::KIND_DEFAULT` as the context kind.
545 546 547 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 545 def and_match(attribute, *values) and_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) end |
#and_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is one of” operator.
518 519 520 521 522 523 524 525 526 527 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 518 def and_match_context(context_kind, attribute, *values) @clauses.push(FlagRuleClause.new( contextKind: context_kind, attribute: attribute, op: 'in', values: values, negate: false )) self end |
#and_not_match(attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is not one of” operator.
This is a shortcut for calling #and_not_match with ‘LaunchDarkly::LDContext::KIND_DEFAULT` as the context kind.
590 591 592 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 590 def and_not_match(attribute, *values) and_not_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) end |
#and_not_match_context(context_kind, attribute, *values) ⇒ FlagRuleBuilder
Adds another clause, using the “is not one of” operator.
563 564 565 566 567 568 569 570 571 572 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 563 def and_not_match_context(context_kind, attribute, *values) @clauses.push(FlagRuleClause.new( contextKind: context_kind, attribute: attribute, op: 'in', values: values, negate: true )) self end |
#build(ri) ⇒ Object
616 617 618 619 620 621 622 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 616 def build(ri) { id: 'rule' + ri.to_s, variation: @variation, clauses: @clauses.map(&:to_h), } end |
#intialize_copy(other) ⇒ Object
499 500 501 502 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 499 def intialize_copy(other) super(other) @clauses = @clauses.clone end |
#then_return(variation) ⇒ FlagBuilder
Finishes defining the rule, specifying the result as either a boolean or a variation index.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
605 606 607 608 609 610 611 612 613 |
# File 'lib/ldclient-rb/integrations/test_data/flag_builder.rb', line 605 def then_return(variation) if LaunchDarkly::Impl::Util.bool? variation @variation = @flag_builder.variation_for_boolean(variation) @flag_builder.boolean_flag.add_rule(self) else @variation = variation @flag_builder.add_rule(self) end end |