rollout 3.1.0 → 3.3.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: f825c30d598b5b2b194b97b0371bbd1ceda8f341458a64b1a601941ee11580eb
4
- data.tar.gz: '038f689c1fe1f5eb3aba0e4eaadcc80da24f320b863a4fffecf6ca3fe4355ba4'
3
+ metadata.gz: ecf20a456dab296cc321049b845972bff0c72075e4bb7e30e2e5314e33cff1b2
4
+ data.tar.gz: d66bce69c2ec03dc790f922635501b970b790886281651708b98fd133d6c3c3e
5
5
  SHA512:
6
- metadata.gz: 2dd85351ad0860f8a2bd86b8b018fad5ed6175751f3018fcc20cad2e96fed7df38de74fc04205207a6de627b168fa0dd04575bf534aa461ed6d4d9b74d36d013
7
- data.tar.gz: ab692a6ae7d929d52df99b7d9de6f0ca41a018c72f5cddc05b3fa37051418ca476b7b89af862c77353e8a82646d0adfa8832a04a8c96b3941a6d865da69626d0
6
+ metadata.gz: dddafc84d403c006b8aafe0ef961b9a883b192a7ba1e4d7816a28bf72c38b60c86b7c86e5e6d10a9a8fa5921b5d8493361023553aecb455f6e2c954eed4bacdd
7
+ data.tar.gz: 1b2de6537a44270239c74d403051eac56cad4580fb995beaaedef5597e354cb7f839cca9b581f814d25451454f0ebfeaa16e0f2ca1e21469106c3413fa4cdee8
@@ -5,18 +5,21 @@ on:
5
5
  tags:
6
6
  - 'rollout/v*'
7
7
  - 'rollout-redis-adapter/v*'
8
+ - 'rollout-active_record-adapter/v*'
8
9
 
9
10
  permissions:
10
11
  contents: write
11
12
  id-token: write
13
+ pull-requests: read
12
14
 
13
15
  jobs:
14
16
  publish:
15
- runs-on: ubuntu-latest
17
+ runs-on: ubuntu-26.04
16
18
  outputs:
17
19
  name: ${{ steps.package.outputs.name }}
18
20
  version: ${{ steps.package.outputs.version }}
19
21
  previous_tag: ${{ steps.package.outputs.previous_tag }}
22
+ paths: ${{ steps.package.outputs.paths }}
20
23
  steps:
21
24
  - name: Checkout code
22
25
  uses: actions/checkout@v5
@@ -30,8 +33,9 @@ jobs:
30
33
  id: package
31
34
  run: |
32
35
  case "$GITHUB_REF_NAME" in
33
- rollout/v*) name=rollout; directory=. ;;
34
- rollout-redis-adapter/v*) name=rollout-redis-adapter; directory=rollout-redis-adapter ;;
36
+ rollout/v*) name=rollout; directory=.; paths="lib rollout.gemspec" ;;
37
+ rollout-redis-adapter/v*) name=rollout-redis-adapter; directory=rollout-redis-adapter; paths=rollout-redis-adapter ;;
38
+ rollout-active_record-adapter/v*) name=rollout-active_record-adapter; directory=rollout-active_record-adapter; paths=rollout-active_record-adapter ;;
35
39
  *) echo "Unexpected tag $GITHUB_REF_NAME" >&2; exit 1 ;;
36
40
  esac
37
41
  version="${GITHUB_REF_NAME##*/v}"
@@ -46,6 +50,7 @@ jobs:
46
50
  echo "version=$version" >> "$GITHUB_OUTPUT"
47
51
  echo "directory=$directory" >> "$GITHUB_OUTPUT"
48
52
  echo "previous_tag=$previous_tag" >> "$GITHUB_OUTPUT"
53
+ echo "paths=$paths" >> "$GITHUB_OUTPUT"
49
54
  - name: Build selected gem
50
55
  working-directory: ${{ steps.package.outputs.directory }}
51
56
  run: gem build "${{ steps.package.outputs.name }}.gemspec"
@@ -57,14 +62,37 @@ jobs:
57
62
 
58
63
  github-release:
59
64
  needs: publish
60
- runs-on: ubuntu-latest
65
+ runs-on: ubuntu-26.04
61
66
  steps:
67
+ - name: Checkout code
68
+ uses: actions/checkout@v5
69
+ with:
70
+ fetch-depth: 0
71
+ # GitHub's generated notes list every PR in the repo between tags; keep
72
+ # only PRs that touched the released gem's files.
73
+ - name: Build release notes
74
+ env:
75
+ GH_TOKEN: ${{ github.token }}
76
+ PREVIOUS_TAG: ${{ needs.publish.outputs.previous_tag }}
77
+ PATHS: ${{ needs.publish.outputs.paths }}
78
+ run: |
79
+ {
80
+ echo "## What's Changed"
81
+ git log --reverse --format=%H "$PREVIOUS_TAG..$GITHUB_REF_NAME" -- $PATHS |
82
+ while read -r sha; do
83
+ gh api "repos/$GITHUB_REPOSITORY/commits/$sha/pulls" \
84
+ --jq '.[] | "* \(.title) by @\(.user.login) in \(.html_url)"'
85
+ done |
86
+ awk '!seen[$0]++'
87
+ echo
88
+ echo "**Full Changelog**: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$PREVIOUS_TAG...$GITHUB_REF_NAME"
89
+ } > release-notes.md
90
+ cat release-notes.md
62
91
  - name: Create GitHub Release
63
- uses: softprops/action-gh-release@v2
92
+ uses: softprops/action-gh-release@v3
64
93
  with:
65
94
  tag_name: ${{ github.ref }}
66
95
  name: ${{ needs.publish.outputs.name }} ${{ needs.publish.outputs.version }}
67
- generate_release_notes: true
68
- previous_tag: ${{ needs.publish.outputs.previous_tag }}
96
+ body_path: release-notes.md
69
97
  draft: false
70
98
  prerelease: false
@@ -10,40 +10,48 @@ on:
10
10
 
11
11
  jobs:
12
12
  core:
13
- runs-on: ubuntu-latest
13
+ runs-on: ubuntu-26.04
14
+ # setup-ruby has no Ruby 3.1 or older builds for ubuntu-26.04, so use the official Ruby images.
15
+ container: ruby:${{ matrix.ruby-version }}
14
16
  strategy:
15
17
  matrix:
16
18
  ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4']
17
19
  steps:
18
20
  - name: Checkout code
19
21
  uses: actions/checkout@v5
20
- - name: Setup Ruby
21
- uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby-version }}
24
- bundler-cache: true
22
+ - name: Install Bundler
23
+ # The Ruby 2.7 and older images ship Bundler 1.17 or 2.1; install the versions setup-ruby used.
24
+ run: |
25
+ case "$RUBY_VERSION" in
26
+ 2.4.*|2.5.*) gem install bundler -v '~> 2.3.0' ;;
27
+ 2.6.*|2.7.*) gem install bundler -v '~> 2.4.0' ;;
28
+ esac
29
+ - name: Install gems
30
+ run: bundle install --jobs 4
25
31
  - name: Run core tests
26
32
  run: |
27
33
  mkdir -p test_results
28
34
  bundle exec rspec spec --format progress --format RspecJunitFormatter --out test_results/rspec.xml
29
35
  - name: Upload test results
30
36
  if: always()
31
- uses: actions/upload-artifact@v5
37
+ uses: actions/upload-artifact@v6
32
38
  with:
33
39
  name: core-test-results-${{ matrix.ruby-version }}
34
40
  path: test_results/rspec.xml
35
41
  retention-days: 30
36
42
 
37
43
  redis:
38
- runs-on: ubuntu-latest
44
+ runs-on: ubuntu-26.04
45
+ # setup-ruby has no Ruby 3.1 or older builds for ubuntu-26.04, so use the official Ruby images.
46
+ container: ruby:${{ matrix.ruby-version }}
39
47
  strategy:
40
48
  matrix:
41
49
  ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4']
50
+ env:
51
+ REDIS_HOST: redis
42
52
  services:
43
53
  redis:
44
54
  image: redis:7-alpine
45
- ports:
46
- - 6379:6379
47
55
  options: >-
48
56
  --health-cmd "redis-cli ping"
49
57
  --health-interval 10s
@@ -52,12 +60,16 @@ jobs:
52
60
  steps:
53
61
  - name: Checkout code
54
62
  uses: actions/checkout@v5
55
- - name: Setup Ruby
56
- uses: ruby/setup-ruby@v1
57
- with:
58
- ruby-version: ${{ matrix.ruby-version }}
59
- working-directory: rollout-redis-adapter
60
- bundler-cache: true
63
+ - name: Install Bundler
64
+ # The Ruby 2.7 and older images ship Bundler 1.17 or 2.1; install the versions setup-ruby used.
65
+ run: |
66
+ case "$RUBY_VERSION" in
67
+ 2.4.*|2.5.*) gem install bundler -v '~> 2.3.0' ;;
68
+ 2.6.*|2.7.*) gem install bundler -v '~> 2.4.0' ;;
69
+ esac
70
+ - name: Install gems
71
+ working-directory: rollout-redis-adapter
72
+ run: bundle install --jobs 4
61
73
  - name: Run Redis adapter tests
62
74
  working-directory: rollout-redis-adapter
63
75
  run: |
@@ -65,8 +77,107 @@ jobs:
65
77
  bundle exec rspec --format progress --format RspecJunitFormatter --out test_results/rspec.xml
66
78
  - name: Upload test results
67
79
  if: always()
68
- uses: actions/upload-artifact@v5
80
+ uses: actions/upload-artifact@v6
69
81
  with:
70
82
  name: redis-test-results-${{ matrix.ruby-version }}
71
83
  path: rollout-redis-adapter/test_results/rspec.xml
72
84
  retention-days: 30
85
+
86
+ active_record:
87
+ runs-on: ubuntu-26.04
88
+ # setup-ruby has no Ruby 3.1 or older builds for ubuntu-26.04, so use the official Ruby images.
89
+ container: ruby:${{ matrix.ruby-version }}
90
+ strategy:
91
+ fail-fast: false
92
+ matrix:
93
+ include:
94
+ - ruby-version: '3.3'
95
+ activerecord: '~> 8.1.0'
96
+ db: sqlite3
97
+ - ruby-version: '3.3'
98
+ activerecord: '~> 8.1.0'
99
+ db: postgresql
100
+ - ruby-version: '3.3'
101
+ activerecord: '~> 8.1.0'
102
+ db: mysql2
103
+ - ruby-version: '3.3'
104
+ activerecord: '~> 7.1.0'
105
+ db: postgresql
106
+ - ruby-version: '3.3'
107
+ activerecord: '~> 7.1.0'
108
+ db: mysql2
109
+ - ruby-version: '3.2'
110
+ activerecord: '~> 8.0.0'
111
+ db: sqlite3
112
+ - ruby-version: '3.1'
113
+ activerecord: '~> 7.2.0'
114
+ db: sqlite3
115
+ - ruby-version: '2.7'
116
+ activerecord: '~> 7.1.0'
117
+ db: sqlite3
118
+ env:
119
+ ACTIVERECORD_VERSION: ${{ matrix.activerecord }}
120
+ ROLLOUT_AR_ADAPTER: ${{ matrix.db }}
121
+ POSTGRES_HOST: postgres
122
+ POSTGRES_USER: postgres
123
+ POSTGRES_PASSWORD: postgres
124
+ POSTGRES_DB: rollout_test
125
+ MYSQL_HOST: mysql
126
+ MYSQL_USER: root
127
+ MYSQL_PASSWORD: root
128
+ MYSQL_DATABASE: rollout_test
129
+ REDIS_HOST: redis
130
+ services:
131
+ redis:
132
+ image: redis:7-alpine
133
+ options: >-
134
+ --health-cmd "redis-cli ping"
135
+ --health-interval 10s
136
+ --health-timeout 5s
137
+ --health-retries 5
138
+ postgres:
139
+ image: postgres:16
140
+ env:
141
+ POSTGRES_USER: postgres
142
+ POSTGRES_PASSWORD: postgres
143
+ POSTGRES_DB: rollout_test
144
+ options: >-
145
+ --health-cmd "pg_isready -U postgres"
146
+ --health-interval 10s
147
+ --health-timeout 5s
148
+ --health-retries 5
149
+ mysql:
150
+ image: mysql:8.0
151
+ env:
152
+ MYSQL_ROOT_PASSWORD: root
153
+ MYSQL_DATABASE: rollout_test
154
+ options: >-
155
+ --health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -proot"
156
+ --health-interval 10s
157
+ --health-timeout 5s
158
+ --health-retries 5
159
+ steps:
160
+ - name: Checkout code
161
+ uses: actions/checkout@v5
162
+ - name: Install Bundler
163
+ # The Ruby 2.7 and older images ship Bundler 1.17 or 2.1; install the versions setup-ruby used.
164
+ run: |
165
+ case "$RUBY_VERSION" in
166
+ 2.4.*|2.5.*) gem install bundler -v '~> 2.3.0' ;;
167
+ 2.6.*|2.7.*) gem install bundler -v '~> 2.4.0' ;;
168
+ esac
169
+ - name: Install gems
170
+ working-directory: rollout-active_record-adapter
171
+ run: bundle install --jobs 4
172
+ - name: Run Active Record adapter tests
173
+ working-directory: rollout-active_record-adapter
174
+ run: |
175
+ mkdir -p test_results
176
+ bundle exec rspec --format progress --format RspecJunitFormatter --out test_results/rspec.xml
177
+ - name: Upload test results
178
+ if: always()
179
+ uses: actions/upload-artifact@v5
180
+ with:
181
+ name: active-record-test-results-${{ matrix.ruby-version }}-${{ matrix.db }}-${{ strategy.job-index }}
182
+ path: rollout-active_record-adapter/test_results/rspec.xml
183
+ retention-days: 30
data/README.md CHANGED
@@ -22,6 +22,11 @@ gem "rollout", "~> 3.1"
22
22
  gem "rollout-redis-adapter", "~> 0.1"
23
23
  ```
24
24
 
25
+ Active Record applications can use `rollout-active_record-adapter` instead of
26
+ `rollout-redis-adapter`. See the [Active Record adapter README](rollout-active_record-adapter/README.md).
27
+ To copy current feature state from Redis, see
28
+ [Migrate from Redis](rollout-active_record-adapter/README.md#migrate-from-redis).
29
+
25
30
  ## How it works
26
31
 
27
32
  Initialize a rollout object. I assign it to a global var.
@@ -29,7 +34,7 @@ Initialize a rollout object. I assign it to a global var.
29
34
  ```ruby
30
35
  require "redis"
31
36
  require "rollout"
32
- require "rollout/adapters/redis"
37
+ require "rollout-redis-adapter"
33
38
 
34
39
  $redis = Redis.new
35
40
  $rollout = Rollout.new(adapter: Rollout::Adapters::Redis.new($redis))
@@ -179,6 +184,63 @@ feature.to_hash
179
184
  # => { percentage: 5.0, groups: [:caretakers], users: ["1"], data: {} }
180
185
  ```
181
186
 
187
+ ## Defining features
188
+
189
+ Describe each feature in its own YAML file, named after the feature. Rollout
190
+ looks in `config/rollouts` under the current directory, which is your app's
191
+ root when you start it from there.
192
+
193
+ ```text
194
+ config/rollouts/
195
+ ├── chat.yml
196
+ └── new_inbox.yml
197
+ ```
198
+
199
+ Only `.yml` files directly in that folder are read. Subfolders, `.yaml` files
200
+ and files starting with a dot are ignored. The file name without `.yml` is the
201
+ feature name, the same one you pass to `$rollout.active?`.
202
+
203
+ ```yaml
204
+ # config/rollouts/chat.yml
205
+ description: Let members chat in groups.
206
+ ```
207
+
208
+ ```yaml
209
+ # config/rollouts/new_inbox.yml
210
+ description: Show conversations as threads.
211
+ owner: messaging
212
+ release_date: "2026-11-15"
213
+ ```
214
+
215
+ ```ruby
216
+ Rollout.definitions.keys # => [:chat, :new_inbox]
217
+ Rollout.definitions[:new_inbox].description # => "Show conversations as threads."
218
+ Rollout.definitions[:new_inbox].path # => "/app/config/rollouts/new_inbox.yml"
219
+ Rollout.definitions[:new_inbox].attributes
220
+ # => { "description" => "Show conversations as threads.", "owner" => "messaging", "release_date" => "2026-11-15" }
221
+ ```
222
+
223
+ Definitions only describe features: they don't create or change stored
224
+ features, and features without a file work as before. Rollout reads
225
+ `description`. Every key, including your own like `owner`, is kept in
226
+ `attributes` with string keys for your application.
227
+
228
+ `Rollout.definitions` reads the folder on every call. A missing folder means no
229
+ definitions. `description` is optional.
230
+
231
+ Files are read with `YAML.safe_load`, so values can be strings, numbers,
232
+ booleans, `null`, lists and mappings. Quote dates and times
233
+ (`release_date: "2026-10-28"`). A file raises `Rollout::InvalidDefinition` if
234
+ it isn't valid YAML, isn't a mapping, uses anything else (an unquoted date, an
235
+ alias, a `:symbol`), or sets `description` to something other than a string.
236
+
237
+ Use another folder, or turn definitions off:
238
+
239
+ ```ruby
240
+ Rollout.definitions_path = Rails.root.join("config", "features")
241
+ Rollout.definitions_path = nil
242
+ ```
243
+
182
244
  ## Namespacing
183
245
 
184
246
  Rollout separates its keys from other keys in the data store using the
@@ -196,7 +258,7 @@ gem "redis-namespace"
196
258
  require "redis"
197
259
  require "redis/namespace"
198
260
  require "rollout"
199
- require "rollout/adapters/redis"
261
+ require "rollout-redis-adapter"
200
262
 
201
263
  $ns = Redis::Namespace.new(Rails.env, redis: $redis)
202
264
  $rollout = Rollout.new(adapter: Rollout::Adapters::Redis.new($ns))
@@ -232,11 +294,12 @@ Rollout 3-compatible UI release before upgrading production.
232
294
 
233
295
  ## Testing
234
296
 
235
- Install dependencies first. Core and the Redis adapter have separate Gemfiles:
297
+ Install dependencies first. Core and the adapter gems have separate Gemfiles:
236
298
 
237
299
  ```bash
238
300
  bundle install
239
301
  bundle install --gemfile=rollout-redis-adapter/Gemfile
302
+ bundle install --gemfile=rollout-active_record-adapter/Gemfile
240
303
  ```
241
304
 
242
305
  Core tests do not need Redis:
@@ -261,6 +324,15 @@ bundle exec rake spec:redis
261
324
  Optional connection settings: `REDIS_HOST`, `REDIS_PORT`, `REDIS_DB`. `REDIS_DB`
262
325
  overrides the default database 7 that is flushed before each example.
263
326
 
327
+ Active Record adapter tests default to SQLite. PostgreSQL and MySQL are also
328
+ supported:
329
+
330
+ ```bash
331
+ bundle exec rake spec:active_record
332
+ ROLLOUT_AR_ADAPTER=postgresql bundle exec rake spec:active_record
333
+ ROLLOUT_AR_ADAPTER=mysql2 bundle exec rake spec:active_record
334
+ ```
335
+
264
336
  ## Releasing
265
337
 
266
338
  Each gem has its own version and tag.
@@ -268,10 +340,12 @@ Each gem has its own version and tag.
268
340
  - Configure a RubyGems trusted publisher for the gem you are releasing. Use
269
341
  repository owner `fetlife`, repository `rollout`, workflow filename
270
342
  `release.yml`, and no GitHub environment.
271
- - Update and commit the version in `lib/rollout/version.rb` or
272
- `rollout-redis-adapter/rollout-redis-adapter.gemspec`.
273
- - Tag the release commit with `rollout/vX.Y.Z` or
274
- `rollout-redis-adapter/vX.Y.Z`, matching the gem version.
343
+ - Update and commit the version in `lib/rollout/version.rb`,
344
+ `rollout-redis-adapter/rollout-redis-adapter.gemspec`, or
345
+ `rollout-active_record-adapter/rollout-active_record-adapter.gemspec`.
346
+ - Tag the release commit with `rollout/vX.Y.Z`,
347
+ `rollout-redis-adapter/vX.Y.Z`, or
348
+ `rollout-active_record-adapter/vX.Y.Z`, matching the gem version.
275
349
  - Push the tag with `git push origin <tag>`. CI publishes the selected gem and
276
350
  creates its GitHub release.
277
351
 
data/Rakefile CHANGED
@@ -16,6 +16,16 @@ namespace :spec do
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ desc "Run Active Record adapter tests"
21
+ task :active_record do
22
+ gemfile = File.expand_path("rollout-active_record-adapter/Gemfile", __dir__)
23
+ Dir.chdir("rollout-active_record-adapter") do
24
+ Bundler.with_unbundled_env do
25
+ sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle exec rspec")
26
+ end
27
+ end
28
+ end
19
29
  end
20
30
 
21
31
  task default: :spec
@@ -2,7 +2,9 @@
2
2
 
3
3
  Rollout 3 keeps feature evaluation in the `rollout` gem and moves Redis
4
4
  persistence to `rollout-redis-adapter`. Existing Redis keys stay in place. This is
5
- not the later Active Record / PostgreSQL migration.
5
+ not a storage migration onto Active Record. For the Active Record adapter
6
+ and Redis cutover, see
7
+ [rollout-active_record-adapter/README.md](../rollout-active_record-adapter/README.md).
6
8
 
7
9
  ## 1. Update dependencies
8
10
 
@@ -39,7 +41,7 @@ $rollout = Rollout.new(
39
41
  # After
40
42
  require "redis"
41
43
  require "rollout"
42
- require "rollout/adapters/redis"
44
+ require "rollout-redis-adapter"
43
45
 
44
46
  $redis = Redis.new
45
47
  $rollout = Rollout.new(
@@ -90,11 +92,18 @@ history.
90
92
 
91
93
  | Operation | Feature state | Per-feature history | Global history |
92
94
  | --- | --- | --- | --- |
93
- | `delete`, logging enabled | Removed | Removed | Retained |
95
+ | `delete`, logging enabled | Removed | Removed | Retained; emits a global `delete` event when `global: true` and the adapter supports event-aware deletion |
94
96
  | `delete`, logging disabled | Removed | Retained | Retained |
95
97
  | `logging.delete` | Unchanged | Removed | Retained |
96
98
  | `clear!` | Removed | Retained | Retained |
97
99
 
100
+ The deletion event includes the feature name, timestamp, and current logging
101
+ context (for example, an actor supplied with `logging.with_context`). Built-in
102
+ adapters write it only when the feature exists and global logging is enabled;
103
+ it is subject to `history_length` like other global events. Older or custom
104
+ adapters without `delete_feature_with_history` retain the previous deletion
105
+ behavior and do not record a deletion event.
106
+
98
107
  `clear!` still resets each feature first, so logging-enabled instances record
99
108
  a reset event before the state is deleted. History remains subject to
100
109
  `history_length`. The Redis registry key is removed after clearing, including
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ class Rollout
6
+ class InvalidDefinition < ArgumentError
7
+ end
8
+
9
+ class Definition
10
+ attr_reader :name, :path, :description, :attributes
11
+
12
+ def self.load(path)
13
+ attributes = YAML.safe_load(File.read(path))
14
+ raise InvalidDefinition, "#{path}: definition must be a mapping" unless attributes.is_a?(Hash)
15
+
16
+ new(name: File.basename(path, '.yml'), attributes: attributes, path: path)
17
+ rescue Psych::Exception => e
18
+ raise InvalidDefinition, "#{path}: #{e.message}"
19
+ end
20
+
21
+ def initialize(name:, attributes: {}, path: nil)
22
+ @name = name.to_sym
23
+ @path = path
24
+ @attributes = attributes.freeze
25
+ @description = attributes['description']
26
+ return if @description.nil? || @description.is_a?(String)
27
+
28
+ raise InvalidDefinition, "#{path || name}: description must be a string"
29
+ end
30
+ end
31
+ end
@@ -74,6 +74,18 @@ class Rollout
74
74
  @adapter.delete_feature_events(feature_name)
75
75
  end
76
76
 
77
+ def delete_event_for(feature_name)
78
+ return unless logging_enabled? && global
79
+
80
+ Event.new(
81
+ feature: feature_name.to_s,
82
+ name: :delete,
83
+ data: {},
84
+ context: current_context,
85
+ created_at: Time.now,
86
+ )
87
+ end
88
+
77
89
  def event_for(before, after)
78
90
  return unless logging_enabled?
79
91
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rollout
4
- VERSION = '3.1.0'
4
+ VERSION = '3.3.0'
5
5
  end
data/lib/rollout.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rollout/definition'
3
4
  require 'rollout/feature'
4
5
  require 'rollout/logging'
5
6
  require 'rollout/version'
@@ -13,6 +14,28 @@ class Rollout
13
14
 
14
15
  RAND_BASE = (2**32 - 1) / 100.0
15
16
 
17
+ class << self
18
+ attr_writer :definitions_path
19
+
20
+ def definitions_path
21
+ return @definitions_path if defined?(@definitions_path)
22
+
23
+ File.expand_path(File.join('config', 'rollouts'))
24
+ end
25
+
26
+ # Reads the folder on every call, so new files show up without a restart.
27
+ def definitions
28
+ folder = definitions_path&.to_s
29
+ return {} unless folder && File.directory?(folder)
30
+
31
+ # Dir.entries rather than a glob, so brackets or asterisks in the folder's path are taken literally.
32
+ Dir.entries(folder).grep(/\A[^.].*\.yml\z/).sort.each_with_object({}) do |file, definitions|
33
+ definition = Definition.load(File.join(folder, file))
34
+ definitions[definition.name] = definition
35
+ end
36
+ end
37
+ end
38
+
16
39
  attr_reader :options, :adapter
17
40
 
18
41
  def initialize(adapter:, **options)
@@ -38,9 +61,16 @@ class Rollout
38
61
  end
39
62
 
40
63
  def delete(feature)
41
- @adapter.delete_feature(feature)
64
+ return @adapter.delete_feature(feature) unless respond_to?(:logging)
42
65
 
43
- if respond_to?(:logging)
66
+ if @adapter.respond_to?(:delete_feature_with_history)
67
+ @adapter.delete_feature_with_history(
68
+ feature,
69
+ event: logging.delete_event_for(feature),
70
+ history_length: logging.history_length,
71
+ )
72
+ else
73
+ @adapter.delete_feature(feature)
44
74
  logging.delete(feature)
45
75
  end
46
76
  end
data/rollout.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split("\n").reject do |file|
17
- file.start_with?('rollout-redis-adapter/')
17
+ file.start_with?('rollout-redis-adapter/', 'rollout-active_record-adapter/')
18
18
  end
19
19
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+ require "tmpdir"
3
+
4
+ RSpec.describe "Rollout.definitions" do
5
+ around do |example|
6
+ Dir.mktmpdir do |dir|
7
+ @dir = dir
8
+ example.run
9
+ end
10
+ end
11
+
12
+ after do
13
+ Rollout.send(:remove_instance_variable, :@definitions_path) if Rollout.instance_variable_defined?(:@definitions_path)
14
+ end
15
+
16
+ def write(name, content)
17
+ File.write(File.join(@dir, name), content)
18
+ end
19
+
20
+ it "loads each .yml file directly in the folder, named after the file" do
21
+ write("chat.yml", "description: Group chat.\ncache: user\n")
22
+ write("notes.yaml", "description: Not loaded.\n")
23
+ FileUtils.mkdir_p(File.join(@dir, "drafts"))
24
+ write("drafts/inbox.yml", "description: Not loaded.\n")
25
+ Rollout.definitions_path = @dir
26
+
27
+ chat = Rollout.definitions.fetch(:chat)
28
+
29
+ expect(Rollout.definitions.keys).to eq [:chat]
30
+ expect(chat.description).to eq "Group chat."
31
+ expect(chat.attributes).to eq("description" => "Group chat.", "cache" => "user")
32
+ expect(chat.path).to eq File.join(@dir, "chat.yml")
33
+ end
34
+
35
+ it "defaults to config/rollouts under the current directory" do
36
+ folder = File.join(@dir, "config", "rollouts")
37
+ FileUtils.mkdir_p(folder)
38
+ File.write(File.join(folder, "chat.yml"), "description: Group chat.\n")
39
+
40
+ Dir.chdir(@dir) do
41
+ expect(Rollout.definitions.keys).to eq [:chat]
42
+ end
43
+ end
44
+
45
+ it "picks up a file added after an earlier call" do
46
+ Rollout.definitions_path = @dir
47
+ expect(Rollout.definitions).to eq({})
48
+
49
+ write("chat.yml", "description: Group chat.\n")
50
+ expect(Rollout.definitions.keys).to eq [:chat]
51
+ end
52
+
53
+ it "takes brackets in the folder's path literally" do
54
+ folder = File.join(@dir, "rollouts[1]")
55
+ FileUtils.mkdir_p(folder)
56
+ File.write(File.join(folder, "chat.yml"), "description: Group chat.\n")
57
+ Rollout.definitions_path = folder
58
+
59
+ expect(Rollout.definitions.keys).to eq [:chat]
60
+ end
61
+
62
+ it "has no definitions when the folder is missing or the path is nil" do
63
+ Rollout.definitions_path = File.join(@dir, "missing")
64
+ expect(Rollout.definitions).to eq({})
65
+
66
+ Rollout.definitions_path = nil
67
+ expect(Rollout.definitions).to eq({})
68
+ end
69
+
70
+ it "names the file that is not valid YAML" do
71
+ write("chat.yml", "description: [unclosed\n")
72
+ Rollout.definitions_path = @dir
73
+
74
+ expect { Rollout.definitions }.to raise_error(Rollout::InvalidDefinition, /chat\.yml/)
75
+ end
76
+
77
+ it "rejects a description that is not a string" do
78
+ write("chat.yml", "description: 42\n")
79
+ Rollout.definitions_path = @dir
80
+
81
+ expect { Rollout.definitions }.to raise_error(Rollout::InvalidDefinition, /description must be a string/)
82
+ end
83
+ end
data/spec/rollout_spec.rb CHANGED
@@ -191,5 +191,56 @@ RSpec.describe Rollout do
191
191
 
192
192
  expect(rollout.logging.events(:chat)).to eq []
193
193
  end
194
+
195
+ it "records a global deletion event with the current context" do
196
+ backend = RolloutMemoryBackend.new
197
+ rollout = described_class.new(adapter: backend, logging: { global: true })
198
+ rollout.activate_percentage(:chat, 25)
199
+
200
+ rollout.logging.with_context(actor: "alice") { rollout.delete(:chat) }
201
+
202
+ event = rollout.logging.global_events.last
203
+ expect(event.name).to eq :delete
204
+ expect(event.feature).to eq "chat"
205
+ expect(event.data).to eq({})
206
+ expect(event.context).to eq(actor: "alice")
207
+ expect(event.created_at).to be_a(Time)
208
+ end
209
+
210
+ it "does not record a deletion event for a missing feature" do
211
+ backend = RolloutMemoryBackend.new
212
+ rollout = described_class.new(adapter: backend, logging: { global: true })
213
+
214
+ rollout.delete(:chat)
215
+
216
+ expect(rollout.logging.global_events).to eq []
217
+ end
218
+
219
+ it "does not record a deletion event when logging is suppressed" do
220
+ backend = RolloutMemoryBackend.new
221
+ rollout = described_class.new(adapter: backend, logging: { global: true })
222
+ rollout.activate_percentage(:chat, 25)
223
+
224
+ rollout.logging.without { rollout.delete(:chat) }
225
+
226
+ expect(rollout.exists?(:chat)).to eq false
227
+ expect(rollout.logging.events(:chat)).to eq []
228
+ expect(rollout.logging.global_events.map(&:name)).to eq [:update]
229
+ end
230
+
231
+ it "preserves deletion behavior for adapters without event-aware deletion" do
232
+ backend_class = Class.new(RolloutMemoryBackend) do
233
+ undef_method :delete_feature_with_history
234
+ end
235
+ backend = backend_class.new
236
+ rollout = described_class.new(adapter: backend, logging: { global: true })
237
+ rollout.activate_percentage(:chat, 25)
238
+
239
+ expect { rollout.delete(:chat) }.not_to raise_error
240
+
241
+ expect(rollout.exists?(:chat)).to eq false
242
+ expect(rollout.logging.events(:chat)).to eq []
243
+ expect(rollout.logging.global_events.map(&:name)).to eq [:update]
244
+ end
194
245
  end
195
246
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ class RolloutMemoryBackend
11
11
  def initialize
12
12
  @features = {}
13
13
  @events = Hash.new { |hash, key| hash[key] = [] }
14
+ @global_events = []
14
15
  end
15
16
 
16
17
  def fetch_feature(name)
@@ -47,7 +48,10 @@ class RolloutMemoryBackend
47
48
  mutation = yield fetch_feature(name)
48
49
  save_feature(mutation.fetch(:state))
49
50
  event = mutation[:event]
50
- @events[name.to_s] << event if event
51
+ if event
52
+ @events[name.to_s] << event
53
+ @global_events << event if mutation[:global]
54
+ end
51
55
  mutation
52
56
  end
53
57
 
@@ -56,7 +60,7 @@ class RolloutMemoryBackend
56
60
  end
57
61
 
58
62
  def global_events(limit: nil)
59
- limited_events([], limit)
63
+ limited_events(@global_events, limit)
60
64
  end
61
65
 
62
66
  def feature_updated_at(_name)
@@ -66,6 +70,16 @@ class RolloutMemoryBackend
66
70
  @events.delete(name.to_s)
67
71
  end
68
72
 
73
+ def delete_feature_with_history(name, event:, history_length:)
74
+ existed = feature_exists?(name)
75
+ delete_feature(name)
76
+ delete_feature_events(name)
77
+ if existed && event
78
+ @global_events << event
79
+ @global_events = @global_events.last(history_length)
80
+ end
81
+ end
82
+
69
83
  private
70
84
 
71
85
  def limited_events(events, limit)
@@ -38,6 +38,13 @@ RSpec.shared_examples "a rollout feature backend" do
38
38
  expect(backend.fetch_features([])).to eq []
39
39
  end
40
40
 
41
+ it "round-trips a double-precision percentage" do
42
+ percentage = 33.333333333333336
43
+ backend.save_feature(Rollout::FeatureState.new(name: :chat, percentage: percentage))
44
+
45
+ expect(backend.fetch_feature(:chat).percentage).to eq percentage
46
+ end
47
+
41
48
  it "does not share nested data with a fetched state" do
42
49
  backend.save_feature(
43
50
  Rollout::FeatureState.new(name: :chat, percentage: 0, data: { "labels" => ["a"] }),
@@ -0,0 +1,174 @@
1
+ RSpec.shared_examples "a rollout history backend" do
2
+ let(:rollout) { Rollout.new(adapter: backend, logging: logging) }
3
+ let(:logging) { true }
4
+ let(:feature) { :foo }
5
+
6
+ it "persists feature events oldest-to-newest" do
7
+ rollout.activate_percentage(feature, 50)
8
+ rollout.activate_percentage(feature, 75)
9
+ rollout.activate_group(feature, :hipsters)
10
+
11
+ events = rollout.logging.events(feature)
12
+ expect(events.map(&:name)).to eq %w[update update update]
13
+ expect(events.map { |event| event.data }).to eq [
14
+ { before: { percentage: 0 }, after: { percentage: 50 } },
15
+ { before: { percentage: 50 }, after: { percentage: 75 } },
16
+ { before: { groups: [] }, after: { groups: ["hipsters"] } },
17
+ ]
18
+ expect(rollout.logging.updated_at(feature)).to_not be_nil
19
+ end
20
+
21
+ it "does not write a history event when a double-precision percentage is unchanged" do
22
+ percentage = 33.333333333333336
23
+ rollout.activate_percentage(feature, percentage)
24
+
25
+ expect do
26
+ rollout.activate_percentage(feature, percentage)
27
+ end.not_to change { rollout.logging.events(feature).count }
28
+
29
+ expect(rollout.get(feature).percentage).to eq percentage
30
+ end
31
+
32
+ it "persists metadata changes and actor context" do
33
+ rollout.logging.with_context(actor: "alice") do
34
+ rollout.with_feature(feature) do |current|
35
+ current.percentage = 25.0
36
+ current.data.update(description: "New navigation")
37
+ end
38
+ end
39
+
40
+ event = rollout.logging.last_event(feature)
41
+ expect(event.data).to eq(
42
+ before: { percentage: 0, "data.description": nil },
43
+ after: { percentage: 25.0, "data.description": "New navigation" },
44
+ )
45
+ expect(event.context).to eq(actor: "alice")
46
+ expect(rollout.logging.events(feature).count).to eq 1
47
+ end
48
+
49
+ context "history truncation" do
50
+ let(:logging) { { history_length: 1 } }
51
+
52
+ it "keeps only the configured number of events" do
53
+ rollout.activate_percentage(feature, 25)
54
+ rollout.activate_percentage(feature, 30)
55
+
56
+ expect(rollout.logging.events(feature).map { |event| event.data[:after][:percentage] }).to eq [30]
57
+ end
58
+ end
59
+
60
+ context "global logs" do
61
+ let(:logging) { { global: true } }
62
+
63
+ it "logs changes across features oldest-to-newest" do
64
+ rollout.activate_percentage("foo", 25)
65
+ rollout.activate_percentage("bar", 30)
66
+ rollout.activate_percentage("baz", 40)
67
+
68
+ expect(rollout.logging.global_events.map(&:feature)).to eq %w[foo bar baz]
69
+ expect(rollout.logging.global_events(limit: 2).map(&:feature)).to eq %w[bar baz]
70
+ end
71
+ end
72
+
73
+ it "removes feature history on delete" do
74
+ rollout.activate_percentage(feature, 25)
75
+ rollout.delete(feature)
76
+
77
+ expect(rollout.logging.events(feature)).to eq []
78
+ end
79
+
80
+ it "records a global-only delete event for an existing feature" do
81
+ logged_rollout = Rollout.new(adapter: backend, logging: { global: true, history_length: 2 })
82
+ logged_rollout.activate_percentage(feature, 25)
83
+ logged_rollout.logging.with_context(actor: "alice") { logged_rollout.delete(feature) }
84
+
85
+ event = logged_rollout.logging.global_events.last
86
+ expect(event.name).to eq "delete"
87
+ expect(event.feature).to eq feature.to_s
88
+ expect(event.data).to eq({})
89
+ expect(event.context).to eq(actor: "alice")
90
+ expect(logged_rollout.logging.events(feature)).to eq []
91
+ expect(logged_rollout.logging.updated_at(feature)).to be_nil
92
+ expect(backend.feature_names.map(&:to_s)).not_to include(feature.to_s)
93
+ end
94
+
95
+ it "does not record deletions of missing features and honors global history length" do
96
+ logged_rollout = Rollout.new(adapter: backend, logging: { global: true, history_length: 1 })
97
+ logged_rollout.activate_percentage(feature, 25)
98
+ logged_rollout.delete(feature)
99
+ expect(logged_rollout.logging.global_events.map(&:name)).to eq ["delete"]
100
+
101
+ logged_rollout.delete(feature)
102
+
103
+ expect(logged_rollout.logging.global_events.map(&:name)).to eq ["delete"]
104
+ end
105
+
106
+ it "does not add a delete event when global history is disabled" do
107
+ logged_rollout = Rollout.new(adapter: backend, logging: { global: false })
108
+ logged_rollout.activate_percentage(feature, 25)
109
+
110
+ logged_rollout.delete(feature)
111
+
112
+ expect(logged_rollout.logging.global_events).to eq []
113
+ expect(logged_rollout.logging.events(feature)).to eq []
114
+ end
115
+
116
+ it "does not retain a delete event when history length is zero" do
117
+ logged_rollout = Rollout.new(adapter: backend, logging: { global: true, history_length: 0 })
118
+ logged_rollout.activate_percentage(feature, 25)
119
+
120
+ logged_rollout.delete(feature)
121
+
122
+ expect(logged_rollout.logging.global_events).to eq []
123
+ expect(logged_rollout.logging.events(feature)).to eq []
124
+ end
125
+
126
+ it "keeps feature history on clear!" do
127
+ rollout.activate_percentage(feature, 25)
128
+ rollout.clear!
129
+
130
+ expect(rollout.features).to eq []
131
+ expect(rollout.logging.events(feature).map { |event| event.data[:after][:percentage] }).to eq [25, 0]
132
+ end
133
+
134
+ it "keeps feature history when deleting without logging" do
135
+ rollout.activate_percentage(feature, 25)
136
+
137
+ Rollout.new(adapter: backend).delete(feature)
138
+
139
+ expect(rollout.exists?(feature)).to be_falsey
140
+ expect(rollout.logging.events(feature)).not_to eq []
141
+ end
142
+
143
+ it "logging.delete removes feature history only" do
144
+ rollout.activate_percentage(feature, 25)
145
+ rollout.logging.delete(feature)
146
+
147
+ expect(rollout.logging.events(feature)).to eq []
148
+ expect(rollout.logging.updated_at(feature)).to be_nil
149
+ expect(rollout.get(feature).percentage).to eq 25
150
+ end
151
+
152
+ it "adapter delete_feature preserves history" do
153
+ rollout.activate_percentage(feature, 25)
154
+ rollout.adapter.delete_feature(feature)
155
+
156
+ expect(rollout.exists?(feature)).to be_falsey
157
+ expect(rollout.logging.events(feature)).not_to eq []
158
+ end
159
+
160
+ it "returns the newest events oldest-to-newest when limited" do
161
+ rollout.activate_percentage(feature, 25)
162
+ rollout.activate_percentage(feature, 50)
163
+ rollout.activate_percentage(feature, 75)
164
+
165
+ expect(rollout.logging.events(feature, limit: 2).map { |event| event.data[:after][:percentage] }).to eq [50, 75]
166
+ expect(rollout.logging.events(feature, limit: 0)).to eq []
167
+ expect(rollout.logging.last_event(feature).data[:after][:percentage]).to eq 75
168
+ end
169
+
170
+ it "rejects an invalid history limit" do
171
+ expect { rollout.logging.events(feature, limit: -1) }.to raise_error(ArgumentError)
172
+ expect { rollout.adapter.feature_events(feature, limit: 1.5) }.to raise_error(ArgumentError)
173
+ end
174
+ end
@@ -0,0 +1,77 @@
1
+ RSpec.shared_examples "a rollout backend integration" do
2
+ let(:rollout) { Rollout.new(adapter: backend) }
3
+
4
+ it "persists combined feature state" do
5
+ rollout.with_feature(:chat) do |feature|
6
+ feature.percentage = 10.5
7
+ feature.groups = [:employees]
8
+ feature.users = ["123"]
9
+ feature.data.update(description: "New navigation", label: :beta)
10
+ end
11
+
12
+ feature = rollout.get(:chat)
13
+ expect(feature.percentage).to eq 10.5
14
+ expect(feature.groups).to eq [:employees]
15
+ expect(feature.users).to eq %w[123]
16
+ expect(feature.data).to eq("description" => "New navigation", "label" => "beta")
17
+ expect(rollout.exists?(:chat)).to eq true
18
+ expect(rollout.features).to eq [:chat]
19
+ end
20
+
21
+ it "persists metadata that contains pipes" do
22
+ rollout.activate_user(:chat, 8)
23
+ rollout.set_feature_data(:chat, "|call||text|" => "a|bunch|of|stuff")
24
+
25
+ expect(rollout.get(:chat).data).to include("|call||text|" => "a|bunch|of|stuff")
26
+ expect(rollout.get(:chat).users).to eq %w[8]
27
+ end
28
+
29
+ it "clears users, groups, percentage, and data on deactivate" do
30
+ rollout.activate_user(:chat, 42)
31
+ rollout.activate_group(:chat, :employees)
32
+ rollout.activate_percentage(:chat, 50)
33
+ rollout.set_feature_data(:chat, description: "foo")
34
+
35
+ rollout.deactivate(:chat)
36
+
37
+ expect(rollout.features).to eq [:chat]
38
+ expect(rollout.get(:chat).to_hash).to eq(
39
+ percentage: 0,
40
+ users: [],
41
+ groups: [],
42
+ data: {},
43
+ )
44
+ end
45
+
46
+ it "keeps users, groups, and data on deactivate_percentage" do
47
+ rollout.activate_user(:chat, 42)
48
+ rollout.activate_group(:chat, :employees)
49
+ rollout.activate_percentage(:chat, 50)
50
+ rollout.set_feature_data(:chat, description: "foo")
51
+
52
+ rollout.deactivate_percentage(:chat)
53
+
54
+ expect(rollout.get(:chat).percentage).to eq 0
55
+ expect(rollout.get(:chat).users).to eq %w[42]
56
+ expect(rollout.get(:chat).groups).to eq [:employees]
57
+ expect(rollout.get(:chat).data).to eq("description" => "foo")
58
+ end
59
+
60
+ it "removes the feature on delete" do
61
+ rollout.activate(:chat)
62
+ rollout.delete(:chat)
63
+
64
+ expect(rollout.features).to eq []
65
+ expect(rollout.exists?(:chat)).to eq false
66
+ expect(rollout.get(:chat).percentage).to eq 0
67
+ end
68
+
69
+ it "clears persisted features" do
70
+ rollout.activate(:signup)
71
+ rollout.activate(:chat)
72
+ rollout.clear!
73
+
74
+ expect(rollout.features).to eq []
75
+ expect(rollout.exists?(:chat)).to eq false
76
+ end
77
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollout
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Golick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-14 00:00:00.000000000 Z
11
+ date: 2026-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: observer
@@ -142,11 +142,13 @@ files:
142
142
  - Rakefile
143
143
  - docs/upgrading-to-v3.md
144
144
  - lib/rollout.rb
145
+ - lib/rollout/definition.rb
145
146
  - lib/rollout/feature.rb
146
147
  - lib/rollout/feature_state.rb
147
148
  - lib/rollout/logging.rb
148
149
  - lib/rollout/version.rb
149
150
  - rollout.gemspec
151
+ - spec/rollout/definition_spec.rb
150
152
  - spec/rollout/feature_spec.rb
151
153
  - spec/rollout/feature_state_spec.rb
152
154
  - spec/rollout/logging_spec.rb
@@ -154,6 +156,8 @@ files:
154
156
  - spec/rollout_spec.rb
155
157
  - spec/spec_helper.rb
156
158
  - spec/support/backend_contract.rb
159
+ - spec/support/history_contract.rb
160
+ - spec/support/rollout_backend_integration.rb
157
161
  homepage: https://github.com/FetLife/rollout
158
162
  licenses:
159
163
  - MIT