flipper 1.4.2 → 1.5.0.rc1
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/README.md +70 -10
- data/lib/flipper/adapter.rb +24 -0
- data/lib/flipper/adapter_builder.rb +12 -1
- data/lib/flipper/adapters/actor_limit.rb +4 -3
- data/lib/flipper/adapters/cache_base.rb +17 -0
- data/lib/flipper/adapters/dual_write.rb +12 -0
- data/lib/flipper/adapters/failover.rb +15 -0
- data/lib/flipper/adapters/failsafe.rb +16 -0
- data/lib/flipper/adapters/http/client.rb +7 -3
- data/lib/flipper/adapters/http/redacted_debug_output.rb +70 -0
- data/lib/flipper/adapters/http.rb +42 -8
- data/lib/flipper/adapters/instrumented.rb +28 -0
- data/lib/flipper/adapters/memoizable.rb +21 -5
- data/lib/flipper/adapters/memory.rb +63 -31
- data/lib/flipper/adapters/poll.rb +51 -6
- data/lib/flipper/adapters/pstore.rb +15 -0
- data/lib/flipper/adapters/read_only.rb +1 -1
- data/lib/flipper/adapters/strict.rb +17 -1
- data/lib/flipper/adapters/sync/feature_synchronizer.rb +3 -1
- data/lib/flipper/adapters/sync/synchronizer.rb +20 -1
- data/lib/flipper/adapters/sync.rb +8 -0
- data/lib/flipper/adapters/wrapper.rb +7 -0
- data/lib/flipper/cli.rb +87 -22
- data/lib/flipper/cloud/configuration.rb +138 -19
- data/lib/flipper/cloud/dsl.rb +6 -0
- data/lib/flipper/cloud/memory_adapter.rb +43 -0
- data/lib/flipper/cloud/message_verifier.rb +1 -0
- data/lib/flipper/cloud/middleware.rb +8 -3
- data/lib/flipper/cloud/migrate.rb +3 -1
- data/lib/flipper/cloud/routes.rb +24 -2
- data/lib/flipper/cloud/shared_memory.rb +84 -0
- data/lib/flipper/cloud/telemetry.rb +56 -28
- data/lib/flipper/cloud/url_validator.rb +26 -0
- data/lib/flipper/cloud.rb +22 -4
- data/lib/flipper/configuration.rb +86 -3
- data/lib/flipper/dsl.rb +47 -3
- data/lib/flipper/engine.rb +64 -8
- data/lib/flipper/errors.rb +18 -0
- data/lib/flipper/export.rb +4 -0
- data/lib/flipper/exporters/json/export.rb +6 -0
- data/lib/flipper/exporters/json/v1.rb +5 -9
- data/lib/flipper/expression/constant.rb +6 -0
- data/lib/flipper/expression.rb +105 -1
- data/lib/flipper/expressions/comparable.rb +5 -0
- data/lib/flipper/expressions/feature_enabled.rb +11 -7
- data/lib/flipper/expressions/number.rb +2 -0
- data/lib/flipper/expressions/percentage.rb +3 -1
- data/lib/flipper/expressions/percentage_of_actors.rb +9 -0
- data/lib/flipper/expressions/random.rb +2 -0
- data/lib/flipper/expressions/sem_ver.rb +24 -0
- data/lib/flipper/expressions/time.rb +9 -1
- data/lib/flipper/feature.rb +153 -43
- data/lib/flipper/feature_check_context.rb +19 -1
- data/lib/flipper/gates/actor.rb +4 -1
- data/lib/flipper/gates/expression.rb +17 -2
- data/lib/flipper/gates/group.rb +1 -1
- data/lib/flipper/gates/percentage_of_actors.rb +19 -2
- data/lib/flipper/gates/percentage_of_time.rb +4 -1
- data/lib/flipper/groups.rb +66 -0
- data/lib/flipper/instrumentation/log_subscriber.rb +6 -1
- data/lib/flipper/instrumentation/subscriber.rb +21 -2
- data/lib/flipper/middleware/memoizer.rb +5 -2
- data/lib/flipper/named_configuration.rb +194 -0
- data/lib/flipper/named_proxy.rb +46 -0
- data/lib/flipper/poller.rb +39 -17
- data/lib/flipper/sem_ver.rb +84 -0
- data/lib/flipper/spec/shared_adapter_specs.rb +40 -0
- data/lib/flipper/sync_version.rb +61 -0
- data/lib/flipper/test_help.rb +50 -0
- data/lib/flipper/typecast.rb +15 -0
- data/lib/flipper/types/group.rb +2 -2
- data/lib/flipper/version.rb +1 -1
- data/lib/flipper.rb +183 -65
- data/lib/generators/flipper/setup_generator.rb +18 -0
- data/lib/generators/flipper/table_prefix.rb +44 -0
- data/lib/generators/flipper/templates/initializer.rb +7 -0
- data/lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb +13 -7
- data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb +12 -7
- data/lib/generators/flipper/update_generator.rb +3 -0
- metadata +42 -171
- data/.codeclimate.yml +0 -3
- data/.github/FUNDING.yml +0 -1
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/ci.yml +0 -110
- data/.github/workflows/examples.yml +0 -105
- data/.github/workflows/release.yml +0 -54
- data/.rspec +0 -1
- data/.superset/config.json +0 -4
- data/CLAUDE.md +0 -93
- data/CODE_OF_CONDUCT.md +0 -46
- data/Dockerfile +0 -27
- data/Gemfile +0 -41
- data/Rakefile +0 -54
- data/benchmark/enabled_ips.rb +0 -10
- data/benchmark/enabled_multiple_actors_ips.rb +0 -20
- data/benchmark/enabled_profile.rb +0 -20
- data/benchmark/instrumentation_ips.rb +0 -21
- data/benchmark/typecast_ips.rb +0 -27
- data/docker-compose.yml +0 -37
- data/docs/DockerCompose.md +0 -18
- data/docs/README.md +0 -1
- data/docs/images/banner.jpg +0 -0
- data/docs/images/flipper_cloud.png +0 -0
- data/examples/api/basic.ru +0 -18
- data/examples/api/custom_memoized.ru +0 -36
- data/examples/api/memoized.ru +0 -42
- data/examples/basic.rb +0 -19
- data/examples/cloud/app.ru +0 -12
- data/examples/cloud/backoff_policy.rb +0 -13
- data/examples/cloud/basic.rb +0 -22
- data/examples/cloud/cloud_setup.rb +0 -20
- data/examples/cloud/forked.rb +0 -36
- data/examples/cloud/import.rb +0 -17
- data/examples/cloud/poll_interval/README.md +0 -111
- data/examples/cloud/poll_interval/client.rb +0 -108
- data/examples/cloud/poll_interval/server.rb +0 -98
- data/examples/cloud/threaded.rb +0 -33
- data/examples/configuring_default.rb +0 -19
- data/examples/dsl.rb +0 -57
- data/examples/enabled_for_actor.rb +0 -37
- data/examples/expressions.rb +0 -237
- data/examples/group.rb +0 -38
- data/examples/group_dynamic_lookup.rb +0 -75
- data/examples/group_with_members.rb +0 -83
- data/examples/importing.rb +0 -29
- data/examples/individual_actor.rb +0 -28
- data/examples/instrumentation.rb +0 -42
- data/examples/instrumentation_last_accessed_at.rb +0 -38
- data/examples/memoizing.rb +0 -35
- data/examples/mirroring.rb +0 -59
- data/examples/percentage_of_actors.rb +0 -31
- data/examples/percentage_of_actors_enabled_check.rb +0 -35
- data/examples/percentage_of_actors_group.rb +0 -35
- data/examples/percentage_of_time.rb +0 -27
- data/examples/strict.rb +0 -18
- data/flipper-cloud.gemspec +0 -19
- data/flipper.gemspec +0 -42
- data/package-lock.json +0 -41
- data/package.json +0 -10
- data/spec/fixtures/environment.rb +0 -1
- data/spec/fixtures/feature.json +0 -31
- data/spec/fixtures/flipper_pstore_1679087600.json +0 -46
- data/spec/flipper/actor_spec.rb +0 -56
- data/spec/flipper/adapter_builder_spec.rb +0 -72
- data/spec/flipper/adapter_spec.rb +0 -166
- data/spec/flipper/adapters/actor_limit_spec.rb +0 -75
- data/spec/flipper/adapters/dual_write_spec.rb +0 -82
- data/spec/flipper/adapters/failover_spec.rb +0 -141
- data/spec/flipper/adapters/failsafe_spec.rb +0 -58
- data/spec/flipper/adapters/http/client_spec.rb +0 -61
- data/spec/flipper/adapters/http_spec.rb +0 -596
- data/spec/flipper/adapters/instrumented_spec.rb +0 -167
- data/spec/flipper/adapters/memoizable_spec.rb +0 -377
- data/spec/flipper/adapters/memory_spec.rb +0 -36
- data/spec/flipper/adapters/operation_logger_spec.rb +0 -128
- data/spec/flipper/adapters/poll_spec.rb +0 -41
- data/spec/flipper/adapters/pstore_spec.rb +0 -16
- data/spec/flipper/adapters/read_only_spec.rb +0 -100
- data/spec/flipper/adapters/strict_spec.rb +0 -122
- data/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +0 -247
- data/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +0 -33
- data/spec/flipper/adapters/sync/synchronizer_spec.rb +0 -175
- data/spec/flipper/adapters/sync_spec.rb +0 -213
- data/spec/flipper/cli_spec.rb +0 -217
- data/spec/flipper/cloud/configuration_spec.rb +0 -251
- data/spec/flipper/cloud/dsl_spec.rb +0 -82
- data/spec/flipper/cloud/message_verifier_spec.rb +0 -104
- data/spec/flipper/cloud/middleware_spec.rb +0 -289
- data/spec/flipper/cloud/migrate_spec.rb +0 -160
- data/spec/flipper/cloud/telemetry/backoff_policy_spec.rb +0 -107
- data/spec/flipper/cloud/telemetry/metric_spec.rb +0 -87
- data/spec/flipper/cloud/telemetry/metric_storage_spec.rb +0 -58
- data/spec/flipper/cloud/telemetry/submitter_spec.rb +0 -145
- data/spec/flipper/cloud/telemetry_spec.rb +0 -208
- data/spec/flipper/cloud_spec.rb +0 -186
- data/spec/flipper/configuration_spec.rb +0 -50
- data/spec/flipper/dsl_spec.rb +0 -346
- data/spec/flipper/engine_spec.rb +0 -374
- data/spec/flipper/export_spec.rb +0 -13
- data/spec/flipper/exporter_spec.rb +0 -16
- data/spec/flipper/exporters/json/export_spec.rb +0 -60
- data/spec/flipper/exporters/json/v1_spec.rb +0 -33
- data/spec/flipper/expression/builder_spec.rb +0 -248
- data/spec/flipper/expression_spec.rb +0 -188
- data/spec/flipper/expressions/all_spec.rb +0 -15
- data/spec/flipper/expressions/any_spec.rb +0 -15
- data/spec/flipper/expressions/boolean_spec.rb +0 -15
- data/spec/flipper/expressions/equal_spec.rb +0 -24
- data/spec/flipper/expressions/greater_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/greater_than_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_spec.rb +0 -32
- data/spec/flipper/expressions/not_equal_spec.rb +0 -15
- data/spec/flipper/expressions/now_spec.rb +0 -11
- data/spec/flipper/expressions/number_spec.rb +0 -21
- data/spec/flipper/expressions/percentage_of_actors_spec.rb +0 -20
- data/spec/flipper/expressions/percentage_spec.rb +0 -15
- data/spec/flipper/expressions/property_spec.rb +0 -13
- data/spec/flipper/expressions/random_spec.rb +0 -9
- data/spec/flipper/expressions/string_spec.rb +0 -11
- data/spec/flipper/expressions/time_spec.rb +0 -29
- data/spec/flipper/feature_check_context_spec.rb +0 -65
- data/spec/flipper/feature_spec.rb +0 -1227
- data/spec/flipper/gate_spec.rb +0 -39
- data/spec/flipper/gate_values_spec.rb +0 -103
- data/spec/flipper/gates/actor_spec.rb +0 -7
- data/spec/flipper/gates/boolean_spec.rb +0 -74
- data/spec/flipper/gates/expression_spec.rb +0 -190
- data/spec/flipper/gates/group_spec.rb +0 -62
- data/spec/flipper/gates/percentage_of_actors_spec.rb +0 -131
- data/spec/flipper/gates/percentage_of_time_spec.rb +0 -37
- data/spec/flipper/identifier_spec.rb +0 -12
- data/spec/flipper/instrumentation/log_subscriber_spec.rb +0 -122
- data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +0 -95
- data/spec/flipper/instrumenters/memory_spec.rb +0 -43
- data/spec/flipper/instrumenters/noop_spec.rb +0 -27
- data/spec/flipper/middleware/memoizer_spec.rb +0 -518
- data/spec/flipper/middleware/setup_env_spec.rb +0 -94
- data/spec/flipper/model/active_record_spec.rb +0 -72
- data/spec/flipper/poller_spec.rb +0 -390
- data/spec/flipper/registry_spec.rb +0 -140
- data/spec/flipper/serializers/gzip_spec.rb +0 -13
- data/spec/flipper/serializers/json_spec.rb +0 -13
- data/spec/flipper/typecast_spec.rb +0 -232
- data/spec/flipper/types/actor_spec.rb +0 -132
- data/spec/flipper/types/boolean_spec.rb +0 -23
- data/spec/flipper/types/group_spec.rb +0 -112
- data/spec/flipper/types/percentage_of_actors_spec.rb +0 -5
- data/spec/flipper/types/percentage_of_time_spec.rb +0 -5
- data/spec/flipper/types/percentage_spec.rb +0 -46
- data/spec/flipper_integration_spec.rb +0 -783
- data/spec/flipper_spec.rb +0 -422
- data/spec/spec_helper.rb +0 -112
- data/spec/support/actor_names.yml +0 -1
- data/spec/support/descriptions.yml +0 -1
- data/spec/support/fail_on_output.rb +0 -8
- data/spec/support/fake_backoff_policy.rb +0 -15
- data/spec/support/fake_udp_socket.rb +0 -27
- data/spec/support/skippable.rb +0 -18
- data/spec/support/spec_helpers.rb +0 -111
- data/test/adapters/actor_limit_test.rb +0 -20
- data/test/adapters/memory_test.rb +0 -9
- data/test/adapters/pstore_test.rb +0 -17
- data/test/test_helper.rb +0 -7
- data/test_rails/generators/flipper/setup_generator_test.rb +0 -69
- data/test_rails/generators/flipper/update_generator_test.rb +0 -96
- data/test_rails/helper.rb +0 -31
- data/test_rails/system/test_help_test.rb +0 -52
data/examples/expressions.rb
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
def assert(value)
|
|
5
|
-
if value
|
|
6
|
-
p value
|
|
7
|
-
else
|
|
8
|
-
puts "Expected true but was #{value}. Please correct."
|
|
9
|
-
exit 1
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def refute(value)
|
|
14
|
-
if value
|
|
15
|
-
puts "Expected false but was #{value}. Please correct."
|
|
16
|
-
exit 1
|
|
17
|
-
else
|
|
18
|
-
p value
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def reset
|
|
23
|
-
Flipper.disable_expression :something
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class User < Struct.new(:id, :flipper_properties)
|
|
27
|
-
include Flipper::Identifier
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Org < Struct.new(:id, :flipper_properties)
|
|
31
|
-
include Flipper::Identifier
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
org = Org.new(1, {
|
|
35
|
-
"type" => "Org",
|
|
36
|
-
"id" => 1,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
user = User.new(1, {
|
|
40
|
-
"type" => "User",
|
|
41
|
-
"id" => 1,
|
|
42
|
-
"plan" => "basic",
|
|
43
|
-
"age" => 39,
|
|
44
|
-
"team_user" => true,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
admin_user = User.new(2, {
|
|
48
|
-
"type" => "User",
|
|
49
|
-
"id" => 2,
|
|
50
|
-
"admin" => true,
|
|
51
|
-
"team_user" => true,
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
other_user = User.new(3, {
|
|
55
|
-
"type" => "User",
|
|
56
|
-
"id" => 3,
|
|
57
|
-
"plan" => "plus",
|
|
58
|
-
"age" => 18,
|
|
59
|
-
"org_admin" => true,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
age_expression = Flipper.property(:age).gte(21)
|
|
63
|
-
plan_expression = Flipper.property(:plan).eq("basic")
|
|
64
|
-
admin_expression = Flipper.property(:admin).eq(true)
|
|
65
|
-
|
|
66
|
-
puts "Single Expression"
|
|
67
|
-
refute Flipper.enabled?(:something, user)
|
|
68
|
-
|
|
69
|
-
puts "Enabling single expression"
|
|
70
|
-
Flipper.enable :something, plan_expression
|
|
71
|
-
assert Flipper.enabled?(:something, user)
|
|
72
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
73
|
-
refute Flipper.enabled?(:something, other_user)
|
|
74
|
-
|
|
75
|
-
puts "Disabling single expression"
|
|
76
|
-
reset
|
|
77
|
-
refute Flipper.enabled?(:something, user)
|
|
78
|
-
|
|
79
|
-
puts "\n\nAny Expression"
|
|
80
|
-
any_expression = Flipper.any(plan_expression, age_expression)
|
|
81
|
-
refute Flipper.enabled?(:something, user)
|
|
82
|
-
|
|
83
|
-
puts "Enabling any expression"
|
|
84
|
-
Flipper.enable :something, any_expression
|
|
85
|
-
assert Flipper.enabled?(:something, user)
|
|
86
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
87
|
-
refute Flipper.enabled?(:something, other_user)
|
|
88
|
-
|
|
89
|
-
puts "Disabling any expression"
|
|
90
|
-
reset
|
|
91
|
-
refute Flipper.enabled?(:something, user)
|
|
92
|
-
|
|
93
|
-
puts "\n\nAll Expression"
|
|
94
|
-
all_expression = Flipper.all(plan_expression, age_expression)
|
|
95
|
-
refute Flipper.enabled?(:something, user)
|
|
96
|
-
|
|
97
|
-
puts "Enabling all expression"
|
|
98
|
-
Flipper.enable :something, all_expression
|
|
99
|
-
assert Flipper.enabled?(:something, user)
|
|
100
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
101
|
-
refute Flipper.enabled?(:something, other_user)
|
|
102
|
-
|
|
103
|
-
puts "Disabling all expression"
|
|
104
|
-
reset
|
|
105
|
-
refute Flipper.enabled?(:something, user)
|
|
106
|
-
|
|
107
|
-
puts "\n\nNested Expression"
|
|
108
|
-
nested_expression = Flipper.any(admin_expression, all_expression)
|
|
109
|
-
refute Flipper.enabled?(:something, user)
|
|
110
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
111
|
-
refute Flipper.enabled?(:something, other_user)
|
|
112
|
-
|
|
113
|
-
puts "Enabling nested expression"
|
|
114
|
-
Flipper.enable :something, nested_expression
|
|
115
|
-
assert Flipper.enabled?(:something, user)
|
|
116
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
117
|
-
refute Flipper.enabled?(:something, other_user)
|
|
118
|
-
|
|
119
|
-
puts "Disabling nested expression"
|
|
120
|
-
reset
|
|
121
|
-
refute Flipper.enabled?(:something, user)
|
|
122
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
123
|
-
refute Flipper.enabled?(:something, other_user)
|
|
124
|
-
|
|
125
|
-
puts "\n\nBoolean Expression"
|
|
126
|
-
boolean_expression = Flipper.boolean(true)
|
|
127
|
-
Flipper.enable :something, boolean_expression
|
|
128
|
-
assert Flipper.enabled?(:something)
|
|
129
|
-
assert Flipper.enabled?(:something, user)
|
|
130
|
-
reset
|
|
131
|
-
|
|
132
|
-
puts "\n\nSet of Actors Expression"
|
|
133
|
-
set_of_actors_expression = Flipper.any(
|
|
134
|
-
Flipper.property(:flipper_id).eq("User;1"),
|
|
135
|
-
Flipper.property(:flipper_id).eq("User;3"),
|
|
136
|
-
)
|
|
137
|
-
Flipper.enable :something, set_of_actors_expression
|
|
138
|
-
assert Flipper.enabled?(:something, user)
|
|
139
|
-
assert Flipper.enabled?(:something, other_user)
|
|
140
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
141
|
-
reset
|
|
142
|
-
|
|
143
|
-
puts "\n\n% of Actors Expression"
|
|
144
|
-
percentage_of_actors = Flipper.property(:flipper_id).percentage_of_actors(30)
|
|
145
|
-
Flipper.enable :something, percentage_of_actors
|
|
146
|
-
refute Flipper.enabled?(:something, user)
|
|
147
|
-
refute Flipper.enabled?(:something, other_user)
|
|
148
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
149
|
-
reset
|
|
150
|
-
|
|
151
|
-
puts "\n\n% of Actors Per Type Expression"
|
|
152
|
-
percentage_of_actors_per_type = Flipper.any(
|
|
153
|
-
Flipper.all(
|
|
154
|
-
Flipper.property(:type).eq("User"),
|
|
155
|
-
Flipper.property(:flipper_id).percentage_of_actors(40),
|
|
156
|
-
),
|
|
157
|
-
Flipper.all(
|
|
158
|
-
Flipper.property(:type).eq("Org"),
|
|
159
|
-
Flipper.property(:flipper_id).percentage_of_actors(10),
|
|
160
|
-
)
|
|
161
|
-
)
|
|
162
|
-
Flipper.enable :something, percentage_of_actors_per_type
|
|
163
|
-
refute Flipper.enabled?(:something, user) # not in the 40% enabled for Users
|
|
164
|
-
assert Flipper.enabled?(:something, other_user)
|
|
165
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
166
|
-
refute Flipper.enabled?(:something, org) # not in the 10% of enabled for Orgs
|
|
167
|
-
reset
|
|
168
|
-
|
|
169
|
-
puts "\n\nPercentage of Time Expression"
|
|
170
|
-
percentage_of_time_expression = Flipper.random(100).lt(50)
|
|
171
|
-
Flipper.enable :something, percentage_of_time_expression
|
|
172
|
-
results = (1..10000).map { |n| Flipper.enabled?(:something, user) }
|
|
173
|
-
enabled, disabled = results.partition { |r| r }
|
|
174
|
-
p enabled: enabled.size
|
|
175
|
-
p disabled: disabled.size
|
|
176
|
-
assert (4_700..5_200).include?(enabled.size)
|
|
177
|
-
assert (4_700..5_200).include?(disabled.size)
|
|
178
|
-
reset
|
|
179
|
-
|
|
180
|
-
puts "\n\nChanging single expression to all expression"
|
|
181
|
-
Flipper.enable :something, plan_expression
|
|
182
|
-
Flipper.enable :something, Flipper.expression(:something).all.add(age_expression)
|
|
183
|
-
assert Flipper.enabled?(:something, user)
|
|
184
|
-
refute Flipper.enabled?(:something, admin_user)
|
|
185
|
-
refute Flipper.enabled?(:something, other_user)
|
|
186
|
-
|
|
187
|
-
puts "\n\nChanging single expression to any expression"
|
|
188
|
-
Flipper.enable :something, plan_expression
|
|
189
|
-
Flipper.enable :something, Flipper.expression(:something).any.add(age_expression, admin_expression)
|
|
190
|
-
assert Flipper.enabled?(:something, user)
|
|
191
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
192
|
-
refute Flipper.enabled?(:something, other_user)
|
|
193
|
-
|
|
194
|
-
puts "\n\nChanging single expression to any expression by adding to condition"
|
|
195
|
-
Flipper.enable :something, plan_expression
|
|
196
|
-
Flipper.enable :something, Flipper.expression(:something).add(admin_expression)
|
|
197
|
-
assert Flipper.enabled?(:something, user)
|
|
198
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
199
|
-
refute Flipper.enabled?(:something, other_user)
|
|
200
|
-
|
|
201
|
-
puts "\n\nEnabling based on time (epoch)"
|
|
202
|
-
scheduled_epoch = Flipper.now.gte(Flipper.time(Time.now.to_i - 86_400))
|
|
203
|
-
Flipper.enable :something, scheduled_epoch
|
|
204
|
-
assert Flipper.enabled?(:something, user)
|
|
205
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
206
|
-
assert Flipper.enabled?(:something, other_user)
|
|
207
|
-
reset
|
|
208
|
-
|
|
209
|
-
puts "\n\nEnabling based on time (datetime)"
|
|
210
|
-
past_time = (Time.now.utc - 86_400).iso8601
|
|
211
|
-
scheduled_datetime = Flipper.now.gte(Flipper.time(past_time))
|
|
212
|
-
Flipper.enable :something, scheduled_datetime
|
|
213
|
-
assert Flipper.enabled?(:something, user)
|
|
214
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
215
|
-
assert Flipper.enabled?(:something, other_user)
|
|
216
|
-
reset
|
|
217
|
-
|
|
218
|
-
puts "\n\nDisabling after a time (expiring feature)"
|
|
219
|
-
future_time = (Time.now.utc + 86_400).iso8601
|
|
220
|
-
expiring_expression = Flipper.now.lt(Flipper.time(future_time))
|
|
221
|
-
Flipper.enable :something, expiring_expression
|
|
222
|
-
assert Flipper.enabled?(:something, user)
|
|
223
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
224
|
-
assert Flipper.enabled?(:something, other_user)
|
|
225
|
-
reset
|
|
226
|
-
|
|
227
|
-
puts "\n\nEnabling within a time window"
|
|
228
|
-
start_time = (Time.now.utc - 86_400).iso8601
|
|
229
|
-
end_time = (Time.now.utc + 86_400).iso8601
|
|
230
|
-
time_window = Flipper.all(
|
|
231
|
-
Flipper.now.gte(Flipper.time(start_time)),
|
|
232
|
-
Flipper.now.lt(Flipper.time(end_time))
|
|
233
|
-
)
|
|
234
|
-
Flipper.enable :something, time_window
|
|
235
|
-
assert Flipper.enabled?(:something, user)
|
|
236
|
-
assert Flipper.enabled?(:something, admin_user)
|
|
237
|
-
assert Flipper.enabled?(:something, other_user)
|
data/examples/group.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
stats = Flipper[:stats]
|
|
5
|
-
|
|
6
|
-
# Register group
|
|
7
|
-
Flipper.register(:admins) do |actor|
|
|
8
|
-
actor.respond_to?(:admin?) && actor.admin?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Some class that represents actor that will be trying to do something
|
|
12
|
-
class User
|
|
13
|
-
attr_reader :id
|
|
14
|
-
|
|
15
|
-
def initialize(id, admin)
|
|
16
|
-
@id = id
|
|
17
|
-
@admin = admin
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Must respond to flipper_id
|
|
21
|
-
alias_method :flipper_id, :id
|
|
22
|
-
|
|
23
|
-
def admin?
|
|
24
|
-
@admin == true
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
admin = User.new(1, true)
|
|
29
|
-
non_admin = User.new(2, false)
|
|
30
|
-
|
|
31
|
-
puts "Stats for admin: #{stats.enabled?(admin)}"
|
|
32
|
-
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"
|
|
33
|
-
|
|
34
|
-
puts "\nEnabling Stats for admins...\n\n"
|
|
35
|
-
stats.enable_group :admins
|
|
36
|
-
|
|
37
|
-
puts "Stats for admin: #{stats.enabled?(admin)}"
|
|
38
|
-
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
stats = Flipper[:stats]
|
|
5
|
-
|
|
6
|
-
# Register group
|
|
7
|
-
Flipper.register(:enabled_team_member) do |actor, context|
|
|
8
|
-
combos = context.actors_value.map { |flipper_id| flipper_id.split(";", 2) }
|
|
9
|
-
team_names = combos.select { |class_name, id| class_name == "Team" }.map { |class_name, id| id }
|
|
10
|
-
teams = team_names.map { |name| Team.find(name) }
|
|
11
|
-
teams.any? { |team| team.member?(actor) }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Some class that represents actor that will be trying to do something
|
|
15
|
-
class User < Struct.new(:id)
|
|
16
|
-
include Flipper::Identifier
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class Team
|
|
20
|
-
include Flipper::Identifier
|
|
21
|
-
attr_reader :name
|
|
22
|
-
|
|
23
|
-
def self.all
|
|
24
|
-
@all ||= {}
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def self.find(name)
|
|
28
|
-
all.fetch(name.to_s)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def initialize(name, members)
|
|
32
|
-
@name = name.to_s
|
|
33
|
-
@members = members
|
|
34
|
-
self.class.all[@name] = self
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def id
|
|
38
|
-
@name
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def member?(actor)
|
|
42
|
-
@members.map(&:id).include?(actor.id)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
jnunemaker = User.new("jnunemaker")
|
|
47
|
-
jbarnette = User.new("jbarnette")
|
|
48
|
-
aroben = User.new("aroben")
|
|
49
|
-
|
|
50
|
-
core_app = Team.new(:core_app, [jbarnette, jnunemaker])
|
|
51
|
-
feature_flags = Team.new(:feature_flags, [aroben, jnunemaker])
|
|
52
|
-
|
|
53
|
-
stats.enable_actor jbarnette
|
|
54
|
-
|
|
55
|
-
actors = [jbarnette, jnunemaker, aroben]
|
|
56
|
-
|
|
57
|
-
actors.each do |actor|
|
|
58
|
-
if stats.enabled?(actor)
|
|
59
|
-
puts "stats are enabled for #{actor.id}"
|
|
60
|
-
else
|
|
61
|
-
puts "stats are NOT enabled for #{actor.id}"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
puts "enabling team_actor group"
|
|
66
|
-
stats.enable_actor core_app
|
|
67
|
-
stats.enable_group :enabled_team_member
|
|
68
|
-
|
|
69
|
-
actors.each do |actor|
|
|
70
|
-
if stats.enabled?(actor)
|
|
71
|
-
puts "stats are enabled for #{actor.id}"
|
|
72
|
-
else
|
|
73
|
-
puts "stats are NOT enabled for #{actor.id}"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
stats = Flipper[:stats]
|
|
5
|
-
|
|
6
|
-
# Register group
|
|
7
|
-
Flipper.register(:team_actor) do |actor|
|
|
8
|
-
actor.is_a?(TeamActor) && actor.allowed?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Some class that represents actor that will be trying to do something
|
|
12
|
-
class User < Struct.new(:id)
|
|
13
|
-
include Flipper::Identifier
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class Team
|
|
17
|
-
attr_reader :name
|
|
18
|
-
|
|
19
|
-
def initialize(name, members)
|
|
20
|
-
@name = name
|
|
21
|
-
@members = members
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def id
|
|
25
|
-
@name
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def member?(actor)
|
|
29
|
-
@members.include?(actor)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class TeamActor
|
|
34
|
-
def initialize(team, actor)
|
|
35
|
-
@team = team
|
|
36
|
-
@actor = actor
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def allowed?
|
|
40
|
-
@team.member?(@actor)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def flipper_id
|
|
44
|
-
"TeamActor:#{@team.id}:#{@actor.id}"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
jnunemaker = User.new(1)
|
|
49
|
-
jbarnette = User.new(2)
|
|
50
|
-
aroben = User.new(3)
|
|
51
|
-
|
|
52
|
-
core_app = Team.new(:core_app, [jbarnette, jnunemaker])
|
|
53
|
-
feature_flags = Team.new(:feature_flags, [aroben, jnunemaker])
|
|
54
|
-
|
|
55
|
-
core_nunes = TeamActor.new(core_app, jnunemaker)
|
|
56
|
-
core_roben = TeamActor.new(core_app, aroben)
|
|
57
|
-
|
|
58
|
-
if stats.enabled?(core_nunes)
|
|
59
|
-
puts "stats are enabled for jnunemaker"
|
|
60
|
-
else
|
|
61
|
-
puts "stats are NOT enabled for jnunemaker"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
if stats.enabled?(core_roben)
|
|
65
|
-
puts "stats are enabled for aroben"
|
|
66
|
-
else
|
|
67
|
-
puts "stats are NOT enabled for aroben"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
puts "enabling team_actor group"
|
|
71
|
-
stats.enable_group :team_actor
|
|
72
|
-
|
|
73
|
-
if stats.enabled?(core_nunes)
|
|
74
|
-
puts "stats are enabled for jnunemaker"
|
|
75
|
-
else
|
|
76
|
-
puts "stats are NOT enabled for jnunemaker"
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
if stats.enabled?(core_roben)
|
|
80
|
-
puts "stats are enabled for aroben"
|
|
81
|
-
else
|
|
82
|
-
puts "stats are NOT enabled for aroben"
|
|
83
|
-
end
|
data/examples/importing.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require_relative 'active_record/ar_setup'
|
|
3
|
-
require 'flipper'
|
|
4
|
-
require 'flipper/adapters/redis'
|
|
5
|
-
require 'flipper/adapters/active_record'
|
|
6
|
-
|
|
7
|
-
# Say you are using redis...
|
|
8
|
-
redis_adapter = Flipper::Adapters::Redis.new(Redis.new)
|
|
9
|
-
redis_flipper = Flipper.new(redis_adapter)
|
|
10
|
-
|
|
11
|
-
# And redis has some stuff enabled...
|
|
12
|
-
redis_flipper.enable(:search)
|
|
13
|
-
redis_flipper.enable_percentage_of_time(:verbose_logging, 5)
|
|
14
|
-
redis_flipper.enable_percentage_of_actors(:new_feature, 5)
|
|
15
|
-
redis_flipper.enable_actor(:issues, Flipper::Actor.new('1'))
|
|
16
|
-
redis_flipper.enable_actor(:issues, Flipper::Actor.new('2'))
|
|
17
|
-
redis_flipper.enable_group(:request_tracing, :staff)
|
|
18
|
-
|
|
19
|
-
# And you would like to switch to active record...
|
|
20
|
-
ar_adapter = Flipper::Adapters::ActiveRecord.new
|
|
21
|
-
ar_flipper = Flipper.new(ar_adapter)
|
|
22
|
-
|
|
23
|
-
# NOTE: This wipes active record clean and copies features/gates from redis into active record.
|
|
24
|
-
ar_flipper.import(redis_flipper)
|
|
25
|
-
|
|
26
|
-
# active record is now identical to redis.
|
|
27
|
-
ar_flipper.features.each do |feature|
|
|
28
|
-
pp feature: feature.key, values: feature.gate_values
|
|
29
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
stats = Flipper[:stats]
|
|
5
|
-
|
|
6
|
-
# Some class that represents what will be trying to do something
|
|
7
|
-
class User
|
|
8
|
-
attr_reader :id
|
|
9
|
-
|
|
10
|
-
def initialize(id)
|
|
11
|
-
@id = id
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Must respond to flipper_id
|
|
15
|
-
alias_method :flipper_id, :id
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
user1 = User.new(1)
|
|
19
|
-
user2 = User.new(2)
|
|
20
|
-
|
|
21
|
-
puts "Stats for user1: #{stats.enabled?(user1)}"
|
|
22
|
-
puts "Stats for user2: #{stats.enabled?(user2)}"
|
|
23
|
-
|
|
24
|
-
puts "\nEnabling stats for user1...\n\n"
|
|
25
|
-
stats.enable(user1)
|
|
26
|
-
|
|
27
|
-
puts "Stats for user1: #{stats.enabled?(user1)}"
|
|
28
|
-
puts "Stats for user2: #{stats.enabled?(user2)}"
|
data/examples/instrumentation.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'securerandom'
|
|
3
|
-
require 'active_support/isolated_execution_state'
|
|
4
|
-
require 'active_support/notifications'
|
|
5
|
-
|
|
6
|
-
class FlipperSubscriber
|
|
7
|
-
def call(*args)
|
|
8
|
-
event = ActiveSupport::Notifications::Event.new(*args)
|
|
9
|
-
puts event.inspect
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
ActiveSupport::Notifications.subscribe(/flipper/, new)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
require 'flipper'
|
|
16
|
-
require 'flipper/adapters/instrumented'
|
|
17
|
-
|
|
18
|
-
# pick an adapter
|
|
19
|
-
adapter = Flipper::Adapters::Memory.new
|
|
20
|
-
|
|
21
|
-
# instrument it if you want, if not you still get the feature instrumentation
|
|
22
|
-
instrumented = Flipper::Adapters::Instrumented.new(adapter, :instrumenter => ActiveSupport::Notifications)
|
|
23
|
-
|
|
24
|
-
# get a handy dsl instance
|
|
25
|
-
flipper = Flipper.new(instrumented, :instrumenter => ActiveSupport::Notifications)
|
|
26
|
-
|
|
27
|
-
# grab a feature
|
|
28
|
-
search = flipper[:search]
|
|
29
|
-
|
|
30
|
-
perform = lambda do
|
|
31
|
-
# check if that feature is enabled
|
|
32
|
-
if search.enabled?
|
|
33
|
-
puts 'Search away!'
|
|
34
|
-
else
|
|
35
|
-
puts 'No search for you!'
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
perform.call
|
|
40
|
-
puts 'Enabling Search...'
|
|
41
|
-
search.enable
|
|
42
|
-
perform.call
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Quick example of how to keep track of when a feature was last checked.
|
|
2
|
-
require 'bundler/setup'
|
|
3
|
-
require 'securerandom'
|
|
4
|
-
require 'active_support/isolated_execution_state'
|
|
5
|
-
require 'active_support/notifications'
|
|
6
|
-
require 'flipper'
|
|
7
|
-
|
|
8
|
-
class FlipperSubscriber
|
|
9
|
-
def self.stats
|
|
10
|
-
@stats ||= {}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call(name, start, finish, id, payload)
|
|
14
|
-
if payload[:operation] == :enabled?
|
|
15
|
-
feature_name = payload.fetch(:feature_name)
|
|
16
|
-
self.class.stats[feature_name] = Time.now
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
ActiveSupport::Notifications.subscribe(/feature_operation.flipper/, new)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
Flipper.configure do |config|
|
|
24
|
-
config.default {
|
|
25
|
-
Flipper.new(config.adapter, instrumenter: ActiveSupport::Notifications)
|
|
26
|
-
}
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
Flipper.enabled?(:search)
|
|
30
|
-
Flipper.enabled?(:booyeah)
|
|
31
|
-
Flipper.enabled?(:hooray)
|
|
32
|
-
sleep 1
|
|
33
|
-
Flipper.enabled?(:booyeah)
|
|
34
|
-
Flipper.enabled?(:hooray)
|
|
35
|
-
sleep 1
|
|
36
|
-
Flipper.enabled?(:hooray)
|
|
37
|
-
|
|
38
|
-
pp FlipperSubscriber.stats
|
data/examples/memoizing.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
require 'flipper/adapters/operation_logger'
|
|
4
|
-
require 'flipper/instrumentation/log_subscriber'
|
|
5
|
-
|
|
6
|
-
Flipper.configure do |config|
|
|
7
|
-
config.adapter do
|
|
8
|
-
# pick an adapter, this uses memory, any will do
|
|
9
|
-
Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Flipper.enable(:foo)
|
|
14
|
-
Flipper.enable(:bar)
|
|
15
|
-
Flipper.disable(:baz)
|
|
16
|
-
Flipper.disable(:wick)
|
|
17
|
-
# reset the operation logging adapter to empty for clarity
|
|
18
|
-
Flipper.adapter.reset
|
|
19
|
-
|
|
20
|
-
# Turn on memoization (the memoizing middleware does this per request).
|
|
21
|
-
Flipper.memoize = true
|
|
22
|
-
|
|
23
|
-
# Preload all the features.
|
|
24
|
-
Flipper.preload_all
|
|
25
|
-
|
|
26
|
-
# Do as many feature checks as your heart desires.
|
|
27
|
-
%w[foo bar baz wick].each do |name|
|
|
28
|
-
Flipper.enabled?(name)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# See that only one operation exists, a get_all (which is the preload_all).
|
|
32
|
-
pp Flipper.adapter.operations
|
|
33
|
-
# [#<Flipper::Adapters::OperationLogger::Operation:0x00007fdcfe1100e8
|
|
34
|
-
# @args=[],
|
|
35
|
-
# @type=:get_all>]
|
data/examples/mirroring.rb
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require_relative 'active_record/ar_setup'
|
|
3
|
-
require 'flipper'
|
|
4
|
-
require 'flipper/adapters/redis'
|
|
5
|
-
require 'flipper/adapters/active_record'
|
|
6
|
-
|
|
7
|
-
# Say you have production...
|
|
8
|
-
production_adapter = Flipper::Adapters::Memory.new
|
|
9
|
-
production = Flipper.new(production_adapter)
|
|
10
|
-
|
|
11
|
-
# And production has some stuff enabled...
|
|
12
|
-
production.enable(:search)
|
|
13
|
-
production.enable_percentage_of_time(:verbose_logging, 5)
|
|
14
|
-
production.enable_percentage_of_actors(:new_feature, 5)
|
|
15
|
-
production.enable_actor(:issues, Flipper::Actor.new('1'))
|
|
16
|
-
production.enable_actor(:issues, Flipper::Actor.new('2'))
|
|
17
|
-
production.enable_group(:request_tracing, :staff)
|
|
18
|
-
|
|
19
|
-
# And you would like to mirror production to staging...
|
|
20
|
-
staging_adapter = Flipper::Adapters::Memory.new
|
|
21
|
-
staging = Flipper.new(staging_adapter)
|
|
22
|
-
staging_export = staging.export
|
|
23
|
-
|
|
24
|
-
puts "Here is the state of the world for staging and production..."
|
|
25
|
-
puts "Staging"
|
|
26
|
-
staging.features.each do |feature|
|
|
27
|
-
pp feature: feature.key, values: feature.gate_values
|
|
28
|
-
end
|
|
29
|
-
puts "Production"
|
|
30
|
-
production.features.each do |feature|
|
|
31
|
-
pp feature: feature.key, values: feature.gate_values
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# NOTE: This wipes active record clean and copies features/gates from redis into active record.
|
|
35
|
-
puts "Mirroring production to staging..."
|
|
36
|
-
staging.import(production.export)
|
|
37
|
-
puts "Staging is now identical to Production."
|
|
38
|
-
|
|
39
|
-
puts "Staging"
|
|
40
|
-
staging.features.each do |feature|
|
|
41
|
-
pp feature: feature.key, values: feature.gate_values
|
|
42
|
-
end
|
|
43
|
-
puts "Production"
|
|
44
|
-
production.features.each do |feature|
|
|
45
|
-
pp feature: feature.key, values: feature.gate_values
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
puts "Restoring staging to original state..."
|
|
49
|
-
staging.import(staging_export)
|
|
50
|
-
puts "Staging restored."
|
|
51
|
-
|
|
52
|
-
puts "Staging"
|
|
53
|
-
staging.features.each do |feature|
|
|
54
|
-
pp feature: feature.key, values: feature.gate_values
|
|
55
|
-
end
|
|
56
|
-
puts "Production"
|
|
57
|
-
production.features.each do |feature|
|
|
58
|
-
pp feature: feature.key, values: feature.gate_values
|
|
59
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
stats = Flipper[:stats]
|
|
5
|
-
|
|
6
|
-
# Some class that represents what will be trying to do something
|
|
7
|
-
class User < Struct.new(:id)
|
|
8
|
-
include Flipper::Identifier
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
total = 100_000
|
|
12
|
-
|
|
13
|
-
# create array of fake users
|
|
14
|
-
users = (1..total).map { |n| User.new(n) }
|
|
15
|
-
|
|
16
|
-
perform_test = lambda { |number|
|
|
17
|
-
Flipper.enable_percentage_of_actors :stats, number
|
|
18
|
-
|
|
19
|
-
enabled = users.map { |user|
|
|
20
|
-
Flipper.enabled?(:stats, user) ? true : nil
|
|
21
|
-
}.compact
|
|
22
|
-
|
|
23
|
-
actual = (enabled.size / total.to_f * 100).round(3)
|
|
24
|
-
|
|
25
|
-
puts "percentage: #{actual.to_s.rjust(6, ' ')} vs #{number.to_s.rjust(3, ' ')}"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
puts "percentage: Actual vs Hoped For"
|
|
29
|
-
[0.001, 0.01, 0.1, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100].each do |number|
|
|
30
|
-
perform_test.call number
|
|
31
|
-
end
|