flipper 1.5.0.rc1 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e5be0aa661d9f18eef6118d787a7ad12f0c7108f8c201e477c89dd396202eb4
4
- data.tar.gz: 2d94c69bc8e9b98de5aa09eb9aaf7d704c0f3078dd8766187fcee3c2b1084c75
3
+ metadata.gz: bcd315c90967e5b1cf80a834bcadda7d0439fced33abf49a76300eca785e8f27
4
+ data.tar.gz: 22f0d9856d41984f0ac35be264bcfb0a07bdef7f5e59211c82c61d8535333ea0
5
5
  SHA512:
6
- metadata.gz: b6c3c00f7ae737d69580e20659c484825011d074fa4d496dcfae06a470c2089ea311b2fb60bc8106de2b883a30aee0fb96eefde6c673eab50e74c1e2bd636e58
7
- data.tar.gz: 83f5ac5a18eabb1452555b111f222196c28fd9365616889ad1d3c2f1642e4548a8abec7286315e799c38b296a10f757fe7c1e2d2e1417ed7135271ce40b5f33c
6
+ metadata.gz: 8e826172032e682aa69f6ae04394636325f3586b1927c3fb46185da2cefd5921b684aab71dd50a9b8586425b8a928fff59c03e55db681f993076f3c319aad142
7
+ data.tar.gz: fa4c786c16e36e48d246e50c673223fe88ea7d024466f807bc4d6b1747abc4a15caaf4267a1423b6713717ca675e7e905537f070a2c1f6ddc2af0c094c94a532
data/lib/flipper/cli.rb CHANGED
@@ -46,9 +46,18 @@ module Flipper
46
46
  c.on('-t NUM', '--percentage-of-time=NUM', Numeric, "#{action} for a percentage of time") do |num|
47
47
  values << percentage(Types::PercentageOfTime, num)
48
48
  end
49
- c.on('-x expressions', '--expression=JSON', "#{action} for the given expression") do |expression|
49
+ c.on('-x expressions', '--expression=JSON', "#{action} for the given expression") do |json|
50
50
  begin
51
- values << Flipper::Expression.build(JSON.parse(expression))
51
+ expression = Flipper::Expression.build(JSON.parse(json))
52
+
53
+ # Check before anything is enabled, so a bad expression doesn't
54
+ # leave the other values given with it half applied.
55
+ raise ArgumentError, "#{expression.value.inspect} is not an expression" unless expression.is_a?(Flipper::Expression)
56
+ if action == "enable" && expression.empty_groups?
57
+ raise ArgumentError, "#{expression.value.inspect} contains empty Any/All groups"
58
+ end
59
+
60
+ values << expression
52
61
  rescue JSON::ParserError => e
53
62
  ui.error "JSON parse error #{e.message}"
54
63
  ui.trace(e)
@@ -136,7 +136,9 @@ module Flipper
136
136
  # Fetch once for both the local adapter and memory.
137
137
  snapshot = Flipper::Adapters::Memory.new(remote.get_all(cache_bust: cache_bust))
138
138
  snapshot.sync_version = remote.sync_version
139
- sync_memory(snapshot)
139
+ # Tracked like a poll's sync, so one that fails partway is synced again.
140
+ @memory.sync(snapshot.sync_version) { sync_memory(snapshot) }
141
+ nil
140
142
  end
141
143
 
142
144
  # Public: The method that will be used to synchronize local adapter with
@@ -247,19 +249,28 @@ module Flipper
247
249
  return Flipper::Adapters::Poll.new(poller, local_adapter) unless @memory
248
250
 
249
251
  Flipper::Adapters::Poll.new(poller, memory_adapter, synchronizer: -> {
250
- sync_poll(poller.adapter)
252
+ sync_poll(poller.adapter, poller.synced_at)
251
253
  })
252
254
  end
253
255
 
254
256
  # Every thread's Poll calls this after each poll. Threads don't wait on
255
257
  # each other, so ones that read while a new version syncs sync it too.
256
- def sync_poll(snapshot)
258
+ # Once the version is synced, one thread per poll checks whether another
259
+ # process stored a different one, so the rest don't query the local
260
+ # adapter. A check that fails gives the poll back to the next thread.
261
+ def sync_poll(snapshot, polled_at)
257
262
  version = snapshot.sync_version
258
- return if @memory.synced?(version) && @store.sync_version == version
263
+ claimed = false
264
+ if @memory.synced?(version)
265
+ claimed = @memory.claim_store_check(polled_at)
266
+ return unless claimed
267
+ return if @store.sync_version == version
268
+ end
259
269
 
260
270
  @memory.sync(version) { sync_memory(snapshot) }
261
271
  rescue StandardError
262
272
  # Reads keep working from memory if the local adapter is down.
273
+ @memory.release_store_check(polled_at) if claimed
263
274
  end
264
275
 
265
276
  def http_adapter
@@ -12,7 +12,7 @@ module Flipper
12
12
 
13
13
  def initialize(source = nil, threadsafe: true)
14
14
  super
15
- @syncing = 0
15
+ @syncing = Hash.new(0)
16
16
  @overlaps = 0
17
17
  @recopy = false
18
18
  @changed_at = 0
@@ -50,23 +50,50 @@ module Flipper
50
50
  !version.nil? && synchronize { @synced_version == version }
51
51
  end
52
52
 
53
+ # Public: Returns true for the first thread to ask about the poll at
54
+ # polled_at, and false for the rest, so one thread per poll checks the
55
+ # local adapter's version. A thread still on an older poll gets false.
56
+ def claim_store_check(polled_at)
57
+ synchronize do
58
+ return false if @store_checked_at && polled_at <= @store_checked_at
59
+ @store_checked_at = polled_at
60
+ true
61
+ end
62
+ end
63
+
64
+ # Public: Gives back a claim whose check failed, so the next thread to
65
+ # read checks the poll at polled_at again.
66
+ def release_store_check(polled_at)
67
+ synchronize { @store_checked_at = nil if @store_checked_at == polled_at }
68
+ end
69
+
53
70
  # Public: Runs the block that syncs version, then records it as synced.
54
- # Records nothing if the block raises or another sync ran at the same
55
- # time, because an older sync can write its flags after a newer one. The
56
- # next poll then syncs again and repairs them.
71
+ # Records nothing if the block raises or a sync of another version ran at
72
+ # the same time, because an older sync can write its flags after a newer
73
+ # one. The next poll then syncs again and repairs them. Threads syncing
74
+ # the same version write the same flags, so they can still record it,
75
+ # but one that raises may have left flags half written, so it forgets
76
+ # the recorded version and keeps syncs still running from recording.
57
77
  def sync(version)
58
78
  alone, overlaps = synchronize do
59
- @syncing += 1
60
- @overlaps += 1 if @syncing > 1
61
- [@syncing == 1, @overlaps]
79
+ other_version = @syncing.any? { |syncing_version, _| syncing_version != version }
80
+ @overlaps += 1 if other_version
81
+ @syncing[version] += 1
82
+ [!other_version, @overlaps]
62
83
  end
63
84
  finished = false
64
85
  yield
65
86
  finished = true
66
87
  ensure
67
88
  synchronize do
68
- @syncing -= 1
69
- @synced_version = version if finished && alone && overlaps == @overlaps
89
+ @syncing[version] -= 1
90
+ @syncing.delete(version) if @syncing[version] <= 0
91
+ if finished
92
+ @synced_version = version if alone && overlaps == @overlaps
93
+ else
94
+ @overlaps += 1
95
+ @synced_version = nil
96
+ end
70
97
  end
71
98
  end
72
99
 
@@ -77,7 +104,7 @@ module Flipper
77
104
  end
78
105
 
79
106
  def now
80
- Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
107
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
81
108
  end
82
109
  end
83
110
  end
@@ -23,8 +23,12 @@ module Flipper
23
23
  /x
24
24
  EMPTY = [].freeze
25
25
 
26
- # Returns a SemVer, or nil when the string isn't a version.
26
+ # Returns a SemVer, or nil when the string isn't a version. Strings with
27
+ # invalid bytes or in encodings that aren't ASCII compatible (like UTF-16)
28
+ # return nil too, since PATTERN can't match them without raising.
27
29
  def self.parse(string)
30
+ return unless string.is_a?(::String) && string.valid_encoding? && string.encoding.ascii_compatible?
31
+
28
32
  match = PATTERN.match(string)
29
33
  return unless match
30
34
 
@@ -24,12 +24,14 @@ module Flipper
24
24
 
25
25
  prune_named_test_adapters(Flipper.configuration).each do |named|
26
26
  test_adapter = named_test_adapters[named]
27
- if test_adapter && test_adapter[:version] == named.version
28
- Flipper.named(named.name).features.each(&:remove) rescue nil
29
- else
30
- # The named configuration changed since we installed the test
31
- # adapter (or we never did), so clean up and install a fresh one.
32
- Flipper.new(test_adapter[:adapter]).features.each(&:remove) if test_adapter
27
+ # Clear the Memory adapter directly. Going through the named DSL can
28
+ # miss features a memoized list doesn't have, or reach the other store
29
+ # of a write-through adapter wrapping Memory.
30
+ Flipper.new(test_adapter[:adapter]).features.each(&:remove) if test_adapter
31
+
32
+ # Install a fresh one if the named configuration changed since we
33
+ # installed the test adapter (or we never did).
34
+ if test_adapter.nil? || test_adapter[:version] != named.version
33
35
  install_named_test_adapter(named)
34
36
  end
35
37
  end
@@ -49,8 +51,13 @@ module Flipper
49
51
  named_configurations.each { |named| install_named_test_adapter(named) }
50
52
  end
51
53
 
54
+ # Kept on the module, not the object that includes it, so each test's
55
+ # flipper_reset sees the adapters flipper_configure installed at boot.
56
+ NAMED_TEST_ADAPTERS = {}
57
+ private_constant :NAMED_TEST_ADAPTERS
58
+
52
59
  def named_test_adapters
53
- @named_test_adapters ||= {}
60
+ NAMED_TEST_ADAPTERS
54
61
  end
55
62
 
56
63
  # Forget test adapters for named configurations that no longer exist and
@@ -82,12 +82,27 @@ module Flipper
82
82
  # Returns a String.
83
83
  def self.to_feature_name(value)
84
84
  # U+2800 renders as a fixed-width blank but is not default-ignorable or whitespace.
85
- value.to_s
85
+ to_utf8(value.to_s)
86
86
  .scrub('')
87
87
  .gsub(/[\p{Default_Ignorable_Code_Point}\p{Cc}\u2800]/, '')
88
88
  .gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
89
89
  end
90
90
 
91
+ # Private: Convert a string to UTF-8 so the unicode regexps above can
92
+ # match it. Binary strings are read as UTF-8, leaving scrub to drop
93
+ # invalid bytes. Encodings with no UTF-8 converter are read as UTF-8 only
94
+ # when their bytes are valid UTF-8, otherwise the name becomes empty.
95
+ def self.to_utf8(value)
96
+ return value if value.encoding == Encoding::UTF_8 || value.ascii_only?
97
+ return String.new(value, encoding: Encoding::UTF_8) if value.encoding == Encoding::BINARY
98
+
99
+ value.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '')
100
+ rescue Encoding::ConverterNotFoundError
101
+ utf8 = String.new(value, encoding: Encoding::UTF_8)
102
+ utf8.valid_encoding? ? utf8 : ''
103
+ end
104
+ private_class_method :to_utf8
105
+
91
106
  def self.features_hash(source)
92
107
  normalized_source = {}
93
108
  (source || {}).each do |feature_key, gates|
@@ -1,5 +1,5 @@
1
1
  module Flipper
2
- VERSION = '1.5.0.rc1'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
 
4
4
  REQUIRED_RUBY_VERSION = '2.6'.freeze
5
5
  NEXT_REQUIRED_RUBY_VERSION = '3.0'.freeze
@@ -3,11 +3,14 @@ require 'active_support/core_ext/string/inflections'
3
3
  module Flipper
4
4
  module Generators
5
5
  module TablePrefix
6
+ # Lowercase so the migration file name matches what Rails' migrator accepts.
7
+ FORMAT = /\A[a-z0-9_]*\z/
8
+
6
9
  def self.included(generator)
7
10
  generator.class_option :table_prefix,
8
11
  type: :string,
9
12
  default: '',
10
- desc: 'Prefix for the flipper_features and flipper_gates tables'
13
+ desc: 'Prefix for the flipper_features and flipper_gates tables, such as cross_app_ (lowercase letters, numbers and underscores)'
11
14
  end
12
15
 
13
16
  private
@@ -24,10 +27,6 @@ module Flipper
24
27
  file_name.sub('flipper', "#{table_prefix}flipper")
25
28
  end
26
29
 
27
- def migration_class_name(class_name)
28
- class_name.sub('Flipper', "#{table_prefix.camelize}Flipper")
29
- end
30
-
31
30
  def feature_index_name
32
31
  :"index_#{table_prefix}flipper_features_on_key" unless table_prefix.empty?
33
32
  end
@@ -37,7 +36,11 @@ module Flipper
37
36
  end
38
37
 
39
38
  def table_prefix
40
- options[:table_prefix].to_s
39
+ prefix = options[:table_prefix].to_s
40
+ unless FORMAT.match?(prefix)
41
+ raise Thor::Error, "--table-prefix must contain only lowercase letters, numbers and underscores (got #{prefix.inspect})"
42
+ end
43
+ prefix
41
44
  end
42
45
  end
43
46
  end
@@ -1,5 +1,5 @@
1
1
  <%
2
- migration_class = migration_class_name('CreateFlipperTables')
2
+ migration_class = migration_class_name
3
3
  feature_table = feature_table_name
4
4
  gate_table = gate_table_name
5
5
  feature_index = feature_index_name
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  <%
4
- migration_class = migration_class_name('ChangeFlipperGatesValueToText')
4
+ migration_class = migration_class_name
5
5
  gate_table = gate_table_name
6
6
  gate_index = gate_index_name
7
7
  %>class <%= migration_class %> < ActiveRecord::Migration<%= migration_version %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.rc1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-24 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -194,7 +194,7 @@ metadata:
194
194
  homepage_uri: https://www.flippercloud.io
195
195
  source_code_uri: https://github.com/flippercloud/flipper
196
196
  bug_tracker_uri: https://github.com/flippercloud/flipper/issues
197
- changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0.rc1
197
+ changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0
198
198
  funding_uri: https://github.com/sponsors/flippercloud
199
199
  post_install_message:
200
200
  rdoc_options: []