flipper 1.4.2 → 1.5.0.rc2
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 +149 -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 +111 -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
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
# Some class that represents what will be trying to do something
|
|
5
|
-
class User
|
|
6
|
-
attr_reader :id
|
|
7
|
-
|
|
8
|
-
def initialize(id)
|
|
9
|
-
@id = id
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Must respond to flipper_id
|
|
13
|
-
alias_method :flipper_id, :id
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# checking a bunch
|
|
17
|
-
total = 20_000
|
|
18
|
-
enabled = []
|
|
19
|
-
percentage_enabled = 10
|
|
20
|
-
|
|
21
|
-
feature = Flipper[:data_migration]
|
|
22
|
-
feature.enable_percentage_of_actors 10
|
|
23
|
-
|
|
24
|
-
(1..total).each do |id|
|
|
25
|
-
user = User.new(id)
|
|
26
|
-
if feature.enabled? user
|
|
27
|
-
enabled << user
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
p actual: enabled.size, expected: total * (percentage_enabled * 0.01)
|
|
32
|
-
|
|
33
|
-
# checking one
|
|
34
|
-
user = User.new(1)
|
|
35
|
-
p user_1_enabled: feature.enabled?(user)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# This example shows how to setup a group that enables a feature for a
|
|
2
|
-
# percentage of actors. It could be combined with other logic to enable a
|
|
3
|
-
# feature for actors in a particular location or on a particular plan, but only
|
|
4
|
-
# for a percentage of them. The percentage is a constant, but could easily be
|
|
5
|
-
# plucked from memcached, redis, mysql or whatever.
|
|
6
|
-
require 'bundler/setup'
|
|
7
|
-
require 'flipper'
|
|
8
|
-
|
|
9
|
-
# Some class that represents what will be trying to do something
|
|
10
|
-
class User < Struct.new(:id)
|
|
11
|
-
include Flipper::Identifier
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
PERCENTAGE = 50
|
|
15
|
-
Flipper.register(:experimental) do |actor|
|
|
16
|
-
if actor.respond_to?(:flipper_id)
|
|
17
|
-
Zlib.crc32(actor.flipper_id.to_s) % 100 < PERCENTAGE
|
|
18
|
-
else
|
|
19
|
-
false
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# enable the experimental group
|
|
24
|
-
Flipper.enable_group :stats, :experimental
|
|
25
|
-
|
|
26
|
-
# create a bunch of fake users and see how many are enabled
|
|
27
|
-
total = 10_000
|
|
28
|
-
users = (1..total).map { |n| User.new(n) }
|
|
29
|
-
enabled = users.map { |user|
|
|
30
|
-
Flipper.enabled?(:stats, user) ? true : nil
|
|
31
|
-
}.compact
|
|
32
|
-
|
|
33
|
-
# show the results
|
|
34
|
-
actual = (enabled.size / total.to_f * 100).round
|
|
35
|
-
puts "percentage: #{actual} vs hoped for: #{PERCENTAGE}"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
logging = Flipper[:logging]
|
|
5
|
-
|
|
6
|
-
perform_test = lambda do |number|
|
|
7
|
-
logging.enable_percentage_of_time number
|
|
8
|
-
|
|
9
|
-
total = 100_000
|
|
10
|
-
enabled = []
|
|
11
|
-
disabled = []
|
|
12
|
-
|
|
13
|
-
enabled = (1..total).map { |n|
|
|
14
|
-
logging.enabled? ? true : nil
|
|
15
|
-
}.compact
|
|
16
|
-
|
|
17
|
-
actual = (enabled.size / total.to_f * 100).round(3)
|
|
18
|
-
|
|
19
|
-
# puts "#{enabled.size} / #{total}"
|
|
20
|
-
puts "percentage: #{actual.to_s.rjust(6, ' ')} vs #{number.to_s.rjust(3, ' ')}"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
puts "percentage: Actual vs Hoped For"
|
|
24
|
-
|
|
25
|
-
[0.001, 0.01, 0.1, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100].each do |number|
|
|
26
|
-
perform_test.call number
|
|
27
|
-
end
|
data/examples/strict.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'flipper'
|
|
3
|
-
|
|
4
|
-
adapter = Flipper::Adapters::Strict.new(Flipper::Adapters::Memory.new)
|
|
5
|
-
flipper = Flipper.new(adapter)
|
|
6
|
-
|
|
7
|
-
begin
|
|
8
|
-
puts "Checking :unknown_feature, which should raise an error."
|
|
9
|
-
flipper.enabled?(:unknown_feature)
|
|
10
|
-
warn "An error was not raised, but should have been"
|
|
11
|
-
exit 1
|
|
12
|
-
rescue Flipper::Adapters::Strict::NotFound => exception
|
|
13
|
-
puts "Ok, the exepcted error was raised: #{exception.message}"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
puts "Flipper.add(:new_feature)"
|
|
17
|
-
flipper.add(:new_feature)
|
|
18
|
-
puts "Flipper.enabled?(:new_feature) => #{flipper.enabled?(:new_feature)}"
|
data/flipper-cloud.gemspec
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/flipper/version', __FILE__)
|
|
3
|
-
require File.expand_path('../lib/flipper/metadata', __FILE__)
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |gem|
|
|
6
|
-
gem.authors = ['John Nunemaker']
|
|
7
|
-
gem.email = 'support@flippercloud.io'
|
|
8
|
-
gem.summary = '[DEPRECATED] This gem has been merged into the `flipper` gem'
|
|
9
|
-
gem.license = 'MIT'
|
|
10
|
-
gem.homepage = 'https://www.flippercloud.io'
|
|
11
|
-
|
|
12
|
-
gem.files = [ 'lib/flipper-cloud.rb', 'lib/flipper/version.rb' ]
|
|
13
|
-
gem.name = 'flipper-cloud'
|
|
14
|
-
gem.require_paths = ['lib']
|
|
15
|
-
gem.version = Flipper::VERSION
|
|
16
|
-
gem.metadata = Flipper::METADATA
|
|
17
|
-
|
|
18
|
-
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
|
19
|
-
end
|
data/flipper.gemspec
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/flipper/version', __FILE__)
|
|
3
|
-
require File.expand_path('../lib/flipper/metadata', __FILE__)
|
|
4
|
-
|
|
5
|
-
plugin_files = []
|
|
6
|
-
plugin_test_files = []
|
|
7
|
-
|
|
8
|
-
Dir['flipper-*.gemspec'].map do |gemspec|
|
|
9
|
-
spec = Gem::Specification.load(gemspec)
|
|
10
|
-
plugin_files << spec.files
|
|
11
|
-
plugin_test_files << spec.files
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
ignored_files = plugin_files
|
|
15
|
-
ignored_files << Dir['script/*']
|
|
16
|
-
ignored_files << '.gitignore'
|
|
17
|
-
ignored_files << 'Guardfile'
|
|
18
|
-
ignored_files.flatten!.uniq!
|
|
19
|
-
|
|
20
|
-
ignored_test_files = plugin_test_files
|
|
21
|
-
ignored_test_files.flatten!.uniq!
|
|
22
|
-
|
|
23
|
-
Gem::Specification.new do |gem|
|
|
24
|
-
gem.authors = ['John Nunemaker']
|
|
25
|
-
gem.email = 'support@flippercloud.io'
|
|
26
|
-
gem.summary = 'Beautiful, performant feature flags for Ruby and Rails.'
|
|
27
|
-
gem.homepage = 'https://www.flippercloud.io/docs'
|
|
28
|
-
gem.license = 'MIT'
|
|
29
|
-
|
|
30
|
-
gem.bindir = "exe"
|
|
31
|
-
gem.executables = `git ls-files -- exe/*`.split("\n").map { |f| File.basename(f) }
|
|
32
|
-
gem.files = `git ls-files`.split("\n") - ignored_files + ['lib/flipper/version.rb']
|
|
33
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - ignored_test_files
|
|
34
|
-
gem.name = 'flipper'
|
|
35
|
-
gem.require_paths = ['lib']
|
|
36
|
-
gem.version = Flipper::VERSION
|
|
37
|
-
gem.metadata = Flipper::METADATA
|
|
38
|
-
|
|
39
|
-
gem.add_dependency 'concurrent-ruby', '< 2'
|
|
40
|
-
|
|
41
|
-
gem.required_ruby_version = ">= #{Flipper::REQUIRED_RUBY_VERSION}"
|
|
42
|
-
end
|
data/package-lock.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "flipper",
|
|
3
|
-
"lockfileVersion": 3,
|
|
4
|
-
"requires": true,
|
|
5
|
-
"packages": {
|
|
6
|
-
"": {
|
|
7
|
-
"hasInstallScript": true,
|
|
8
|
-
"dependencies": {
|
|
9
|
-
"@popperjs/core": "^2.11.8",
|
|
10
|
-
"bootstrap": "^5.3.3"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"node_modules/@popperjs/core": {
|
|
14
|
-
"version": "2.11.8",
|
|
15
|
-
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
|
16
|
-
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
|
|
17
|
-
"funding": {
|
|
18
|
-
"type": "opencollective",
|
|
19
|
-
"url": "https://opencollective.com/popperjs"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"node_modules/bootstrap": {
|
|
23
|
-
"version": "5.3.3",
|
|
24
|
-
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.3.tgz",
|
|
25
|
-
"integrity": "sha512-8HLCdWgyoMguSO9o+aH+iuZ+aht+mzW0u3HIMzVu7Srrpv7EBBxTnrFlSCskwdY1+EOFQSm7uMJhNQHkdPcmjg==",
|
|
26
|
-
"funding": [
|
|
27
|
-
{
|
|
28
|
-
"type": "github",
|
|
29
|
-
"url": "https://github.com/sponsors/twbs"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "opencollective",
|
|
33
|
-
"url": "https://opencollective.com/bootstrap"
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@popperjs/core": "^2.11.8"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
data/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Placeholder for config/environment.rb
|
data/spec/fixtures/feature.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"key": "my_feature",
|
|
3
|
-
"state": "on",
|
|
4
|
-
"gates": [
|
|
5
|
-
{
|
|
6
|
-
"key": "boolean",
|
|
7
|
-
"name": "boolean",
|
|
8
|
-
"value": "true"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"key": "groups",
|
|
12
|
-
"name": "group",
|
|
13
|
-
"value": []
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"key": "actors",
|
|
17
|
-
"name": "actor",
|
|
18
|
-
"value": []
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"key": "percentage_of_actors",
|
|
22
|
-
"name": "percentage_of_actors",
|
|
23
|
-
"value": null
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"key": "percentage_of_time",
|
|
27
|
-
"name": "percentage_of_time",
|
|
28
|
-
"value": null
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"features": {
|
|
4
|
-
"search": {
|
|
5
|
-
"boolean": null,
|
|
6
|
-
"actors": [
|
|
7
|
-
"john",
|
|
8
|
-
"another",
|
|
9
|
-
"testing"
|
|
10
|
-
],
|
|
11
|
-
"percentage_of_actors": null,
|
|
12
|
-
"percentage_of_time": null,
|
|
13
|
-
"groups": [
|
|
14
|
-
"admins"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"new_pricing": {
|
|
18
|
-
"boolean": "true",
|
|
19
|
-
"actors": [],
|
|
20
|
-
"percentage_of_actors": null,
|
|
21
|
-
"percentage_of_time": null,
|
|
22
|
-
"groups": []
|
|
23
|
-
},
|
|
24
|
-
"google_analytics_tag": {
|
|
25
|
-
"boolean": null,
|
|
26
|
-
"actors": [],
|
|
27
|
-
"percentage_of_actors": "100",
|
|
28
|
-
"percentage_of_time": null,
|
|
29
|
-
"groups": []
|
|
30
|
-
},
|
|
31
|
-
"help_scout_tag": {
|
|
32
|
-
"boolean": null,
|
|
33
|
-
"actors": [],
|
|
34
|
-
"percentage_of_actors": null,
|
|
35
|
-
"percentage_of_time": "50",
|
|
36
|
-
"groups": []
|
|
37
|
-
},
|
|
38
|
-
"nope": {
|
|
39
|
-
"boolean": null,
|
|
40
|
-
"actors": [],
|
|
41
|
-
"percentage_of_actors": null,
|
|
42
|
-
"percentage_of_time": null,
|
|
43
|
-
"groups": []
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
data/spec/flipper/actor_spec.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Actor do
|
|
2
|
-
it 'initializes with and knows flipper_id' do
|
|
3
|
-
actor = described_class.new("User;235")
|
|
4
|
-
expect(actor.flipper_id).to eq("User;235")
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
describe '#eql?' do
|
|
8
|
-
it 'returns true if same class and flipper_id' do
|
|
9
|
-
actor1 = described_class.new("User;235")
|
|
10
|
-
actor2 = described_class.new("User;235")
|
|
11
|
-
expect(actor1.eql?(actor2)).to be(true)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'returns false if same class but different flipper_id' do
|
|
15
|
-
actor1 = described_class.new("User;235")
|
|
16
|
-
actor2 = described_class.new("User;1")
|
|
17
|
-
expect(actor1.eql?(actor2)).to be(false)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'returns false for different class' do
|
|
21
|
-
actor1 = described_class.new("User;235")
|
|
22
|
-
actor2 = Struct.new(:flipper_id).new("User;235")
|
|
23
|
-
expect(actor1.eql?(actor2)).to be(false)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe '#==' do
|
|
28
|
-
it 'returns true if same class and flipper_id' do
|
|
29
|
-
actor1 = described_class.new("User;235")
|
|
30
|
-
actor2 = described_class.new("User;235")
|
|
31
|
-
expect(actor1.==(actor2)).to be(true)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'returns false if same class but different flipper_id' do
|
|
35
|
-
actor1 = described_class.new("User;235")
|
|
36
|
-
actor2 = described_class.new("User;1")
|
|
37
|
-
expect(actor1.==(actor2)).to be(false)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'returns false for different class' do
|
|
41
|
-
actor1 = described_class.new("User;235")
|
|
42
|
-
actor2 = Struct.new(:flipper_id).new("User;235")
|
|
43
|
-
expect(actor1.==(actor2)).to be(false)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe '#hash' do
|
|
48
|
-
it 'returns a hash-value based on the flipper id' do
|
|
49
|
-
h = {
|
|
50
|
-
described_class.new("User;123") => true
|
|
51
|
-
}
|
|
52
|
-
expect(h).to have_key(described_class.new("User;123"))
|
|
53
|
-
expect(h).not_to have_key(described_class.new("User;456"))
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::AdapterBuilder do
|
|
2
|
-
describe "#initialize" do
|
|
3
|
-
it "instance_eval's block with no arg" do
|
|
4
|
-
called = false
|
|
5
|
-
self_in_block = nil
|
|
6
|
-
|
|
7
|
-
described_class.new do
|
|
8
|
-
called = true
|
|
9
|
-
self_in_block = self
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
expect(self_in_block).to be_instance_of(described_class)
|
|
13
|
-
expect(called).to be(true)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "evals block with arg" do
|
|
17
|
-
called = false
|
|
18
|
-
self_outside_block = self
|
|
19
|
-
self_in_block = nil
|
|
20
|
-
|
|
21
|
-
described_class.new do |arg|
|
|
22
|
-
called = true
|
|
23
|
-
self_in_block = self
|
|
24
|
-
expect(arg).to be_instance_of(described_class)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
expect(self_in_block).to be(self_outside_block)
|
|
28
|
-
expect(called).to be(true)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "#use" do
|
|
33
|
-
it "wraps the store adapter with the given adapter" do
|
|
34
|
-
subject.use(Flipper::Adapters::Memoizable)
|
|
35
|
-
subject.use(Flipper::Adapters::Strict, :warn)
|
|
36
|
-
|
|
37
|
-
memoizable_adapter = subject.to_adapter
|
|
38
|
-
strict_adapter = memoizable_adapter.adapter
|
|
39
|
-
memory_adapter = strict_adapter.adapter
|
|
40
|
-
|
|
41
|
-
expect(memoizable_adapter).to be_instance_of(Flipper::Adapters::Memoizable)
|
|
42
|
-
expect(strict_adapter).to be_instance_of(Flipper::Adapters::Strict)
|
|
43
|
-
expect(strict_adapter.handler).to be(:warn)
|
|
44
|
-
expect(memory_adapter).to be_instance_of(Flipper::Adapters::Memory)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "passes block to adapter initializer" do
|
|
48
|
-
expected_block = lambda {}
|
|
49
|
-
adapter_class = double('adapter class')
|
|
50
|
-
|
|
51
|
-
subject.use(adapter_class, &expected_block)
|
|
52
|
-
|
|
53
|
-
expect(adapter_class).to receive(:new) { |&block| expect(block).to be(expected_block) }.and_return(:adapter)
|
|
54
|
-
expect(subject.to_adapter).to be(:adapter)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe "#store" do
|
|
59
|
-
it "defaults to memory adapter" do
|
|
60
|
-
expect(subject.to_adapter).to be_instance_of(Flipper::Adapters::Memory)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "only saves one store" do
|
|
64
|
-
require "flipper/adapters/pstore"
|
|
65
|
-
subject.store(Flipper::Adapters::PStore)
|
|
66
|
-
expect(subject.to_adapter).to be_instance_of(Flipper::Adapters::PStore)
|
|
67
|
-
|
|
68
|
-
subject.store(Flipper::Adapters::Memory)
|
|
69
|
-
expect(subject.to_adapter).to be_instance_of(Flipper::Adapters::Memory)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Adapter do
|
|
2
|
-
let(:source_flipper) { build_flipper }
|
|
3
|
-
let(:destination_flipper) { build_flipper }
|
|
4
|
-
let(:default_config) do
|
|
5
|
-
{
|
|
6
|
-
boolean: nil,
|
|
7
|
-
groups: Set.new,
|
|
8
|
-
actors: Set.new,
|
|
9
|
-
expression: nil,
|
|
10
|
-
percentage_of_actors: nil,
|
|
11
|
-
percentage_of_time: nil,
|
|
12
|
-
}
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '.default_config' do
|
|
16
|
-
it 'returns default config' do
|
|
17
|
-
adapter_class = Class.new do
|
|
18
|
-
include Flipper::Adapter
|
|
19
|
-
end
|
|
20
|
-
expect(adapter_class.default_config).to eq(default_config)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe '#default_config' do
|
|
25
|
-
it 'returns default config' do
|
|
26
|
-
adapter_class = Class.new do
|
|
27
|
-
include Flipper::Adapter
|
|
28
|
-
end
|
|
29
|
-
expect(adapter_class.new.default_config).to eq(default_config)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe '#import' do
|
|
34
|
-
it 'returns true' do
|
|
35
|
-
result = destination_flipper.import(source_flipper)
|
|
36
|
-
expect(result).to be(true)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'can import from one adapter to another' do
|
|
40
|
-
source_flipper.enable(:search)
|
|
41
|
-
destination_flipper.import(source_flipper)
|
|
42
|
-
expect(destination_flipper[:search].boolean_value).to eq(true)
|
|
43
|
-
expect(destination_flipper.features.map(&:key).sort).to eq(%w(search))
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'can import features that have been added but their state is off' do
|
|
47
|
-
source_flipper.add(:search)
|
|
48
|
-
destination_flipper.import(source_flipper)
|
|
49
|
-
expect(destination_flipper.features.map(&:key)).to eq(["search"])
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'can import multiple features' do
|
|
53
|
-
source_flipper.enable(:yep)
|
|
54
|
-
source_flipper.enable_group(:preview_features, :developers)
|
|
55
|
-
source_flipper.enable_group(:preview_features, :marketers)
|
|
56
|
-
source_flipper.enable_group(:preview_features, :company)
|
|
57
|
-
source_flipper.enable_group(:preview_features, :early_access)
|
|
58
|
-
source_flipper.enable_actor(:preview_features, Flipper::Actor.new('1'))
|
|
59
|
-
source_flipper.enable_actor(:preview_features, Flipper::Actor.new('2'))
|
|
60
|
-
source_flipper.enable_actor(:preview_features, Flipper::Actor.new('3'))
|
|
61
|
-
source_flipper.enable_percentage_of_actors(:issues_next, 25)
|
|
62
|
-
source_flipper.enable_percentage_of_time(:verbose_logging, 5)
|
|
63
|
-
|
|
64
|
-
destination_flipper.import(source_flipper)
|
|
65
|
-
|
|
66
|
-
feature = destination_flipper[:yep]
|
|
67
|
-
expect(feature.boolean_value).to be(true)
|
|
68
|
-
expect(feature.groups_value).to eq(Set[])
|
|
69
|
-
expect(feature.actors_value).to eq(Set[])
|
|
70
|
-
expect(feature.percentage_of_actors_value).to be(0)
|
|
71
|
-
expect(feature.percentage_of_time_value).to be(0)
|
|
72
|
-
|
|
73
|
-
feature = destination_flipper[:preview_features]
|
|
74
|
-
expect(feature.boolean_value).to be(false)
|
|
75
|
-
expect(feature.actors_value).to eq(Set['1', '2', '3'])
|
|
76
|
-
expected_groups = Set['developers', 'marketers', 'company', 'early_access']
|
|
77
|
-
expect(feature.groups_value).to eq(expected_groups)
|
|
78
|
-
expect(feature.percentage_of_actors_value).to be(0)
|
|
79
|
-
expect(feature.percentage_of_time_value).to be(0)
|
|
80
|
-
|
|
81
|
-
feature = destination_flipper[:issues_next]
|
|
82
|
-
expect(feature.boolean_value).to eq(false)
|
|
83
|
-
expect(feature.actors_value).to eq(Set.new)
|
|
84
|
-
expect(feature.groups_value).to eq(Set.new)
|
|
85
|
-
expect(feature.percentage_of_actors_value).to be(25)
|
|
86
|
-
expect(feature.percentage_of_time_value).to be(0)
|
|
87
|
-
|
|
88
|
-
feature = destination_flipper[:verbose_logging]
|
|
89
|
-
expect(feature.boolean_value).to eq(false)
|
|
90
|
-
expect(feature.actors_value).to eq(Set.new)
|
|
91
|
-
expect(feature.groups_value).to eq(Set.new)
|
|
92
|
-
expect(feature.percentage_of_actors_value).to be(0)
|
|
93
|
-
expect(feature.percentage_of_time_value).to be(5)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it 'wipes existing enablements for adapter' do
|
|
97
|
-
destination_flipper.enable(:stats)
|
|
98
|
-
destination_flipper.enable_percentage_of_time(:verbose_logging, 5)
|
|
99
|
-
source_flipper.enable_percentage_of_time(:stats, 5)
|
|
100
|
-
source_flipper.enable_percentage_of_actors(:verbose_logging, 25)
|
|
101
|
-
|
|
102
|
-
destination_flipper.import(source_flipper)
|
|
103
|
-
|
|
104
|
-
feature = destination_flipper[:stats]
|
|
105
|
-
expect(feature.boolean_value).to be(false)
|
|
106
|
-
expect(feature.percentage_of_time_value).to be(5)
|
|
107
|
-
|
|
108
|
-
feature = destination_flipper[:verbose_logging]
|
|
109
|
-
expect(feature.percentage_of_time_value).to be(0)
|
|
110
|
-
expect(feature.percentage_of_actors_value).to be(25)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it 'wipes existing features for adapter' do
|
|
114
|
-
destination_flipper.add(:stats)
|
|
115
|
-
destination_flipper.import(source_flipper)
|
|
116
|
-
expect(destination_flipper.features.map(&:key)).to eq([])
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'can import an export' do
|
|
120
|
-
source_flipper.enable(:search)
|
|
121
|
-
source_flipper.enable(:google_analytics, Flipper::Actor.new("User;1"))
|
|
122
|
-
|
|
123
|
-
destination_flipper.import(source_flipper.export)
|
|
124
|
-
|
|
125
|
-
feature = destination_flipper[:search]
|
|
126
|
-
expect(feature.boolean_value).to be(true)
|
|
127
|
-
|
|
128
|
-
feature = destination_flipper[:google_analytics]
|
|
129
|
-
expect(feature.actors_value).to eq(Set["User;1"])
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
describe "#export" do
|
|
134
|
-
it "exports features" do
|
|
135
|
-
source_flipper.enable(:search)
|
|
136
|
-
export = source_flipper.export
|
|
137
|
-
expect(export.features.dig("search", :boolean)).to eq("true")
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "exports with arguments" do
|
|
141
|
-
source_flipper.enable(:search)
|
|
142
|
-
export = source_flipper.export(format: :json, version: 1)
|
|
143
|
-
expect(export.features.dig("search", :boolean)).to eq("true")
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
describe "#adapter_stack" do
|
|
148
|
-
it "returns the adapter name for a simple adapter" do
|
|
149
|
-
adapter = Flipper::Adapters::Memory.new
|
|
150
|
-
expect(adapter.adapter_stack).to eq("memory")
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it "returns the chain for wrapped adapters" do
|
|
154
|
-
memory = Flipper::Adapters::Memory.new
|
|
155
|
-
memoizable = Flipper::Adapters::Memoizable.new(memory)
|
|
156
|
-
expect(memoizable.adapter_stack).to eq("memoizable -> memory")
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "returns the chain for deeply nested adapters" do
|
|
160
|
-
memory = Flipper::Adapters::Memory.new
|
|
161
|
-
strict = Flipper::Adapters::Strict.new(memory)
|
|
162
|
-
memoizable = Flipper::Adapters::Memoizable.new(strict)
|
|
163
|
-
expect(memoizable.adapter_stack).to eq("memoizable -> strict -> memory")
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require "flipper/adapters/actor_limit"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper::Adapters::ActorLimit do
|
|
4
|
-
it_should_behave_like 'a flipper adapter' do
|
|
5
|
-
let(:limit) { 5 }
|
|
6
|
-
let(:adapter) { Flipper::Adapters::ActorLimit.new(Flipper::Adapters::Memory.new, limit) }
|
|
7
|
-
|
|
8
|
-
subject { adapter }
|
|
9
|
-
|
|
10
|
-
describe '#enable' do
|
|
11
|
-
it "fails when limit exceeded" do
|
|
12
|
-
5.times { |i| feature.enable Flipper::Actor.new("User;#{i}") }
|
|
13
|
-
|
|
14
|
-
expect {
|
|
15
|
-
feature.enable Flipper::Actor.new("User;6")
|
|
16
|
-
}.to raise_error(Flipper::Adapters::ActorLimit::LimitExceeded)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "allows exceeding limit when in sync mode" do
|
|
20
|
-
5.times { |i| feature.enable Flipper::Actor.new("User;#{i}") }
|
|
21
|
-
|
|
22
|
-
described_class.with_sync_mode do
|
|
23
|
-
expect {
|
|
24
|
-
feature.enable Flipper::Actor.new("User;6")
|
|
25
|
-
}.not_to raise_error
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe '.sync_mode' do
|
|
32
|
-
after do
|
|
33
|
-
described_class.sync_mode = nil
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'defaults to nil/falsy' do
|
|
37
|
-
expect(described_class.sync_mode).to be_falsy
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'can be set and read' do
|
|
41
|
-
described_class.sync_mode = true
|
|
42
|
-
expect(described_class.sync_mode).to be true
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe '.with_sync_mode' do
|
|
47
|
-
after do
|
|
48
|
-
described_class.sync_mode = nil
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'sets sync_mode to true within block' do
|
|
52
|
-
described_class.with_sync_mode do
|
|
53
|
-
expect(described_class.sync_mode).to be true
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'restores previous value after block' do
|
|
58
|
-
expect(described_class.sync_mode).to be_falsy
|
|
59
|
-
described_class.with_sync_mode { }
|
|
60
|
-
expect(described_class.sync_mode).to be_falsy
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'restores previous value even on exception' do
|
|
64
|
-
expect {
|
|
65
|
-
described_class.with_sync_mode { raise "boom" }
|
|
66
|
-
}.to raise_error("boom")
|
|
67
|
-
expect(described_class.sync_mode).to be_falsy
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'returns the block result' do
|
|
71
|
-
result = described_class.with_sync_mode { 42 }
|
|
72
|
-
expect(result).to eq(42)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|