flipper 1.5.0.rc2 → 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: 28e85c4c99a54920a81f1fb1a1345e0d8e1492d149907636dbbf2d5218bad0eb
4
- data.tar.gz: 1550707f666c820f6fa225637239b9084b87bddb69f5290755d8d4021e2be351
3
+ metadata.gz: bcd315c90967e5b1cf80a834bcadda7d0439fced33abf49a76300eca785e8f27
4
+ data.tar.gz: 22f0d9856d41984f0ac35be264bcfb0a07bdef7f5e59211c82c61d8535333ea0
5
5
  SHA512:
6
- metadata.gz: e92e10677da51eb7a7da7336bd42aa9b37410f396dfbb04467d87c0ce390096781153f493270d52f8b46f6a0721e04e165416b6ec2968ea743106eb03d81f3f6
7
- data.tar.gz: 8094d3cdb80b21bb47d7e4ab51886a9efe43e934341c3210513f885244922585cc9db352a546b8abb010cb7a70c563b80de3b4693d9631e437331c45a7551c11
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)
@@ -104,7 +104,7 @@ module Flipper
104
104
  end
105
105
 
106
106
  def now
107
- Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
107
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
108
108
  end
109
109
  end
110
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.rc2'.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.rc2
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.rc2
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: []