growthbook 1.2.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/growthbook/conditions.rb +409 -102
- data/lib/growthbook/context.rb +362 -60
- data/lib/growthbook/feature_repository.rb +24 -2
- data/lib/growthbook/feature_result.rb +10 -2
- data/lib/growthbook/feature_rule.rb +63 -19
- data/lib/growthbook/fnv.rb +5 -2
- data/lib/growthbook/inline_experiment.rb +37 -1
- data/lib/growthbook/inline_experiment_result.rb +20 -11
- data/lib/growthbook/payload_reducer.rb +278 -0
- data/lib/growthbook/sticky_bucket_service.rb +45 -0
- data/lib/growthbook/util.rb +36 -0
- data/lib/growthbook.rb +48 -0
- metadata +36 -6
data/lib/growthbook.rb
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
# The GrowthBook SDK
|
|
4
4
|
module Growthbook
|
|
5
|
+
# Partially evaluate a targeting condition when only some attributes are known,
|
|
6
|
+
# e.g. on a server. Attributes missing from `attributes` are unknown.
|
|
7
|
+
#
|
|
8
|
+
# @param attributes [Hash] The known attributes
|
|
9
|
+
# @param condition [Hash] The targeting condition
|
|
10
|
+
# @param saved_groups [Hash] The payload's saved groups
|
|
11
|
+
# @return [true, false, Hash] true or false once the result can't depend on the
|
|
12
|
+
# unknown attributes, otherwise the condition minus every branch already decided
|
|
13
|
+
def self.prune_condition(attributes, condition, saved_groups = {})
|
|
14
|
+
Growthbook::Conditions.prune_condition(
|
|
15
|
+
Growthbook::Conditions.parse_condition(attributes || {}),
|
|
16
|
+
Growthbook::Conditions.parse_condition(condition),
|
|
17
|
+
saved_groups || {}
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Shrink a features payload for a user whose attributes are only partly known,
|
|
22
|
+
# e.g. on a server that bootstraps a client-side SDK. The result evaluates the
|
|
23
|
+
# same as the full payload for anyone who agrees with the known attributes.
|
|
24
|
+
#
|
|
25
|
+
# @param payload [Hash] A decrypted features payload, as returned by the SDK API
|
|
26
|
+
# (features, experiments, savedGroups, contextualBandits)
|
|
27
|
+
# @param attributes [Hash] The attributes known for the user
|
|
28
|
+
# @param include [Hash] Keep only features and experiments that match every filter:
|
|
29
|
+
# `projects`, `tags` (arrays, any one value is enough) and `customFields` (a hash of field to array of values)
|
|
30
|
+
# @param exclude [Hash] Drop features and experiments that match any filter, with the same keys as `include`
|
|
31
|
+
# @param prerequisites ['keep', 'filter'] With 'keep' (the default), the prerequisites of kept features and
|
|
32
|
+
# experiments are kept even when the filters drop them. With 'filter', only holdouts are.
|
|
33
|
+
# @return [Hash] The reduced payload, with every other key of `payload` unchanged
|
|
34
|
+
def self.reduce_payload(payload, attributes: {}, include: {}, exclude: {}, prerequisites: 'keep')
|
|
35
|
+
Growthbook::PayloadReducer.new(
|
|
36
|
+
Growthbook::Conditions.parse_condition(payload),
|
|
37
|
+
attributes: Growthbook::Conditions.parse_condition(attributes || {}),
|
|
38
|
+
include: payload_filters(include),
|
|
39
|
+
exclude: payload_filters(exclude),
|
|
40
|
+
prerequisites: prerequisites
|
|
41
|
+
).reduce
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Filters with string keys, accepting `custom_fields` for `customFields`
|
|
45
|
+
def self.payload_filters(filters)
|
|
46
|
+
filters = Growthbook::Conditions.parse_condition(filters || {})
|
|
47
|
+
filters['customFields'] = filters.delete('custom_fields') if filters.key?('custom_fields')
|
|
48
|
+
filters
|
|
49
|
+
end
|
|
50
|
+
private_class_method :payload_filters
|
|
5
51
|
end
|
|
6
52
|
|
|
7
53
|
require 'growthbook/conditions'
|
|
@@ -14,6 +60,8 @@ require 'growthbook/feature_rule'
|
|
|
14
60
|
require 'growthbook/fnv'
|
|
15
61
|
require 'growthbook/inline_experiment'
|
|
16
62
|
require 'growthbook/inline_experiment_result'
|
|
63
|
+
require 'growthbook/payload_reducer'
|
|
17
64
|
require 'growthbook/tracking_callback'
|
|
18
65
|
require 'growthbook/util'
|
|
19
66
|
require 'growthbook/feature_usage_callback'
|
|
67
|
+
require 'growthbook/sticky_bucket_service'
|
metadata
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: growthbook
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GrowthBook
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-11-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: base64
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bigdecimal
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
13
41
|
- !ruby/object:Gem::Dependency
|
|
14
42
|
name: rspec
|
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -98,6 +126,8 @@ files:
|
|
|
98
126
|
- lib/growthbook/fnv.rb
|
|
99
127
|
- lib/growthbook/inline_experiment.rb
|
|
100
128
|
- lib/growthbook/inline_experiment_result.rb
|
|
129
|
+
- lib/growthbook/payload_reducer.rb
|
|
130
|
+
- lib/growthbook/sticky_bucket_service.rb
|
|
101
131
|
- lib/growthbook/tracking_callback.rb
|
|
102
132
|
- lib/growthbook/util.rb
|
|
103
133
|
homepage: https://github.com/growthbook/growthbook-ruby
|
|
@@ -105,7 +135,7 @@ licenses:
|
|
|
105
135
|
- MIT
|
|
106
136
|
metadata:
|
|
107
137
|
rubygems_mfa_required: 'true'
|
|
108
|
-
post_install_message:
|
|
138
|
+
post_install_message:
|
|
109
139
|
rdoc_options: []
|
|
110
140
|
require_paths:
|
|
111
141
|
- lib
|
|
@@ -120,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
150
|
- !ruby/object:Gem::Version
|
|
121
151
|
version: '0'
|
|
122
152
|
requirements: []
|
|
123
|
-
rubygems_version: 3.4.
|
|
124
|
-
signing_key:
|
|
153
|
+
rubygems_version: 3.4.19
|
|
154
|
+
signing_key:
|
|
125
155
|
specification_version: 4
|
|
126
156
|
summary: GrowthBook SDK for Ruby
|
|
127
157
|
test_files: []
|