Class: Growthbook::FeatureRule
- Inherits:
-
Object
- Object
- Growthbook::FeatureRule
- Defined in:
- lib/growthbook/feature_rule.rb
Overview
Internal class that overrides the default value of a Feature based on a set of requirements.
Instance Attribute Summary collapse
-
#condition ⇒ Hash?
readonly
Optional targeting condition.
-
#coverage ⇒ Float?
readonly
What percent of users should be included in the experiment (between 0 and 1, inclusive).
-
#filters ⇒ Filter[]?
readonly
Array of filters to apply to the rule.
-
#force ⇒ T?
readonly
Immediately force a specific value (ignore every other option besides condition and coverage).
-
#hash_attribute ⇒ String?
readonly
What user attribute should be used to assign variations (defaults to id).
-
#hash_version ⇒ Integer?
readonly
The hash version to use (default to 1).
-
#key ⇒ String?
readonly
The globally unique tracking key for the experiment (default to the feature key).
-
#meta ⇒ VariationMeta[]?
readonly
Meta info about the experiment variations.
-
#name ⇒ String?
readonly
Human-readable name for the experiment.
-
#namespace ⇒ String?
readonly
Adds the experiment to a namespace.
-
#phase ⇒ String?
readonly
The phase id of the experiment.
-
#range ⇒ BucketRange?
readonly
A more precise version of coverage.
-
#ranges ⇒ BucketRanges[]?
readonly
Ranges for experiment variations.
-
#seed ⇒ String?
readonly
Seed to use for hashing.
-
#tracks ⇒ TrackData[]?
readonly
Array of tracking calls to fire.
-
#variations ⇒ T[]?
readonly
Run an experiment (A/B test) and randomly choose between these variations.
-
#weights ⇒ Float[]?
readonly
How to weight traffic between variations.
Instance Method Summary collapse
- #experiment? ⇒ Boolean
- #force? ⇒ Boolean
-
#initialize(rule) ⇒ FeatureRule
constructor
A new instance of FeatureRule.
- #to_experiment(feature_key) ⇒ Growthbook::InlineExperiment?
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(rule) ⇒ FeatureRule
Returns a new instance of FeatureRule.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/growthbook/feature_rule.rb', line 57 def initialize(rule) @coverage = get_option(rule, :coverage) @force = get_option(rule, :force) @variations = get_option(rule, :variations) @key = get_option(rule, :key) @weights = get_option(rule, :weights) @namespace = get_option(rule, :namespace) @hash_attribute = get_option(rule, :hash_attribute) || get_option(rule, :hashAttribute) @hash_version = get_option(rule, :hash_version) || get_option(rule, :hashVersion) @range = get_option(rule, :range) @ranges = get_option(rule, :ranges) = get_option(rule, :meta) @filters = get_option(rule, :filters) @seed = get_option(rule, :seed) @name = get_option(rule, :name) @phase = get_option(rule, :phase) @tracks = get_option(rule, :tracks) cond = get_option(rule, :condition) @condition = Growthbook::Conditions.parse_condition(cond) unless cond.nil? end |
Instance Attribute Details
#condition ⇒ Hash? (readonly)
Returns Optional targeting condition.
7 8 9 |
# File 'lib/growthbook/feature_rule.rb', line 7 def condition @condition end |
#coverage ⇒ Float? (readonly)
Returns What percent of users should be included in the experiment (between 0 and 1, inclusive).
10 11 12 |
# File 'lib/growthbook/feature_rule.rb', line 10 def coverage @coverage end |
#filters ⇒ Filter[]? (readonly)
Returns Array of filters to apply to the rule.
43 44 45 |
# File 'lib/growthbook/feature_rule.rb', line 43 def filters @filters end |
#force ⇒ T? (readonly)
Returns Immediately force a specific value (ignore every other option besides condition and coverage).
13 14 15 |
# File 'lib/growthbook/feature_rule.rb', line 13 def force @force end |
#hash_attribute ⇒ String? (readonly)
Returns What user attribute should be used to assign variations (defaults to id).
28 29 30 |
# File 'lib/growthbook/feature_rule.rb', line 28 def hash_attribute @hash_attribute end |
#hash_version ⇒ Integer? (readonly)
Returns The hash version to use (default to 1).
31 32 33 |
# File 'lib/growthbook/feature_rule.rb', line 31 def hash_version @hash_version end |
#key ⇒ String? (readonly)
Returns The globally unique tracking key for the experiment (default to the feature key).
19 20 21 |
# File 'lib/growthbook/feature_rule.rb', line 19 def key @key end |
#meta ⇒ VariationMeta[]? (readonly)
Returns Meta info about the experiment variations.
40 41 42 |
# File 'lib/growthbook/feature_rule.rb', line 40 def end |
#name ⇒ String? (readonly)
Returns Human-readable name for the experiment.
49 50 51 |
# File 'lib/growthbook/feature_rule.rb', line 49 def name @name end |
#namespace ⇒ String? (readonly)
Returns Adds the experiment to a namespace.
25 26 27 |
# File 'lib/growthbook/feature_rule.rb', line 25 def namespace @namespace end |
#phase ⇒ String? (readonly)
Returns The phase id of the experiment.
52 53 54 |
# File 'lib/growthbook/feature_rule.rb', line 52 def phase @phase end |
#range ⇒ BucketRange? (readonly)
Returns A more precise version of coverage.
34 35 36 |
# File 'lib/growthbook/feature_rule.rb', line 34 def range @range end |
#ranges ⇒ BucketRanges[]? (readonly)
Returns Ranges for experiment variations.
37 38 39 |
# File 'lib/growthbook/feature_rule.rb', line 37 def ranges @ranges end |
#seed ⇒ String? (readonly)
Returns Seed to use for hashing.
46 47 48 |
# File 'lib/growthbook/feature_rule.rb', line 46 def seed @seed end |
#tracks ⇒ TrackData[]? (readonly)
Returns Array of tracking calls to fire.
55 56 57 |
# File 'lib/growthbook/feature_rule.rb', line 55 def tracks @tracks end |
#variations ⇒ T[]? (readonly)
Returns Run an experiment (A/B test) and randomly choose between these variations.
16 17 18 |
# File 'lib/growthbook/feature_rule.rb', line 16 def variations @variations end |
#weights ⇒ Float[]? (readonly)
Returns How to weight traffic between variations. Must add to 1.
22 23 24 |
# File 'lib/growthbook/feature_rule.rb', line 22 def weights @weights end |
Instance Method Details
#experiment? ⇒ Boolean
100 101 102 103 104 |
# File 'lib/growthbook/feature_rule.rb', line 100 def experiment? return false if @variations.nil? !@variations&.empty? end |
#force? ⇒ Boolean
106 107 108 |
# File 'lib/growthbook/feature_rule.rb', line 106 def force? !experiment? && !@force.nil? end |
#to_experiment(feature_key) ⇒ Growthbook::InlineExperiment?
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/growthbook/feature_rule.rb', line 80 def to_experiment(feature_key) return nil unless @variations Growthbook::InlineExperiment.new( key: @key || feature_key, variations: @variations, coverage: @coverage, weights: @weights, hash_attribute: @hash_attribute, hash_version: @hash_version, namespace: @namespace, meta: , ranges: @ranges, filters: @filters, name: @name, phase: @phase, seed: @seed ) end |
#to_json(*_args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/growthbook/feature_rule.rb', line 110 def to_json(*_args) { 'condition' => @condition, 'coverage' => @coverage, 'force' => @force, 'variations' => @variations, 'key' => @key, 'weights' => @weights, 'namespace' => @namespace, 'hashAttribute' => @hash_attribute, 'range' => @range, 'ranges' => @ranges, 'meta' => , 'filters' => @filters, 'seed' => @seed, 'name' => @name, 'phase' => @phase, 'tracks' => @tracks }.compact end |