request_migrations 1.1.0 → 1.1.2

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: c2224934d0be51149ebf90a756ae9cfd9172ee83310609c9cfc94c49c4c75166
4
- data.tar.gz: 3de2f808de4c02d7de89ec9baae0b5d68cadab94d8118e13688a941de791d3cf
3
+ metadata.gz: 9a4bcd66e61c3fbda8dd1a2d68c84953bd44cfb2b1c9fed79e90a0965cb1853d
4
+ data.tar.gz: b772558c45d89f41d9c0eceab0b118e141fd93f31d40e037b810b669f2dfc997
5
5
  SHA512:
6
- metadata.gz: 944f3e23fe55b3d9eb56cdf0491871bfecea72a5c9a57b15f8827152b7cf5a21ab0e0ac6c1f254a9afabe4fc980562b864e96a2868ec864a314d41876e1af987
7
- data.tar.gz: e3fa22992ac3aadcd34ce860310f6a496f4aa7f54179090863bcf993582e2c757fa07677862973b817edc2d209b289284e19ec040249c62011ad20ceb41ee0c6
6
+ metadata.gz: d6727a31da8a3bbf69d013af4c68a873ff7c1c09a17f407906f27469df8c822aa070207e9ab6fa39299e3ef2960c8184efa954f9417c6678c3f242808add7cfa
7
+ data.tar.gz: 7086a2c8604219bef3d9b7040897f0faa30cb2ff19d800ea1ab9011db3dad2d11b25d8e77b2e98b09175b90e2ad93180664278c60ea5af9d47fbe4c52c6b8388
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.2
4
+
5
+ - Remove deprecated `ActiveSupport::Configurable`.
6
+
7
+ ## 1.1.1
8
+
9
+ - Fix minimum required Ruby version from v3.0 to v3.1.
10
+
11
+ ## 1.1.0
12
+
13
+ - Add `request_migrations/testing` for unit testing migrations.
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  - Fix application order of `request` migrations.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # request_migrations
2
2
 
3
+ [![CI](https://github.com/keygen-sh/request_migrations/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/request_migrations/actions)
3
4
  [![Gem Version](https://badge.fury.io/rb/request_migrations.svg)](https://badge.fury.io/rb/request_migrations)
4
5
 
5
6
  **Make breaking API changes without breaking things!** Use `request_migrations` to craft
@@ -13,9 +14,32 @@ to serve millions of API requests per day.
13
14
 
14
15
  Sponsored by:
15
16
 
16
- [![Keygen logo](https://user-images.githubusercontent.com/6979737/175406169-bd8bf064-7343-4bd1-94b7-a773ecec07b8.png)](https://keygen.sh)
17
-
18
- _A software licensing and distribution API built for developers._
17
+ <a href="https://keygen.sh?ref=request_migrations">
18
+ <div>
19
+ <img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
20
+ </div>
21
+ </a>
22
+
23
+ _A fair source software licensing and distribution API._
24
+
25
+ Links:
26
+
27
+ - [Installing request_migrations](#installation)
28
+ - [Supported Ruby versions](#supported-rubies)
29
+ - [RubyDoc](#documentation)
30
+ - [Usage](#usage)
31
+ - [Response migrations](#response-migrations)
32
+ - [Request migrations](#request-migrations)
33
+ - [Data migrations](#data-migrations)
34
+ - [Routing constraints](#routing-constraints)
35
+ - [Configuration](#configuration)
36
+ - [Version formats](#version-formats)
37
+ - [Testing](#testing)
38
+ - [Tips and tricks](#tips-and-tricks)
39
+ - [Examples](#examples)
40
+ - [Credits](#credits)
41
+ - [Contributing](#contributing)
42
+ - [License](#license)
19
43
 
20
44
  ## Installation
21
45
 
@@ -39,8 +63,9 @@ $ gem install request_migrations
39
63
 
40
64
  ## Supported Rubies
41
65
 
42
- `request_migrations` supports Ruby 3. We encourage you to upgrade if you're on an older
43
- version. Ruby 3 provides a lot of great features, like better pattern matching.
66
+ **`request_migrations` supports Ruby 3.1 and above.** We encourage you to upgrade if you're on an older
67
+ version. Ruby 3 provides a lot of great features, like better pattern matching and a new shorthand
68
+ hash syntax.
44
69
 
45
70
  ## Documentation
46
71
 
@@ -124,8 +149,8 @@ end
124
149
 
125
150
  As you can see, with pattern matching, it makes creating migrations for certain
126
151
  resources simple. Here, we've defined a migration that only runs for the `users#show`
127
- and `me#show` resources, and only when the response is successfuly. In addition,
128
- the data is only migrated when the response body contains a user.
152
+ resource, and only when the response is successful. In addition, the data is
153
+ only migrated when the response body contains a user.
129
154
 
130
155
  Next, we'll need to configure `request_migrations` via an initializer under
131
156
  `initializers/request_migrations.rb`:
@@ -198,6 +223,8 @@ The gem makes no assumption on a response's content type or what the migration
198
223
  will do. You could, for example, migrate the response body, or mutate the
199
224
  headers, or even change the response's status code.
200
225
 
226
+ The `response` method can be used multiple times per-migration.
227
+
201
228
  ### Request migrations
202
229
 
203
230
  Request migrations define a change on a request. For example, modifying a request's
@@ -225,6 +252,8 @@ headers. It's up to you, all it does is provide the request.
225
252
 
226
253
  Request migrations should [avoid using the `migrate` method](#avoid-migrate-for-request-migrations).
227
254
 
255
+ The `request` method can be used multiple times.
256
+
228
257
  ### Data migrations
229
258
 
230
259
  In our first scenario, where we combined our user's name attributes, we defined
@@ -292,10 +321,15 @@ end
292
321
 
293
322
  This will apply the block defined in `migrate` onto our data. With that,
294
323
  we've successfully applied a migration to both our API responses, as well
295
- as to the webhook events we send. In this case, if our `event` matches the
296
- our user shape, e.g. `type: 'user'`, then the migration will be applied.
324
+ as to the webhook events we send. In this case, if our event data matches
325
+ our expected data shape, e.g. `type: 'user'`, then the migration will
326
+ be applied.
297
327
 
298
- In addition to data migrations, this allows for easier testing.
328
+ In addition to data migrations, this allows for easier [testing](#testing).
329
+
330
+ The `migrate` method can be used multiple times per-migration to e.g.
331
+ match and migrate on different shapes of data. For a JSON:API app,
332
+ for example, you could migrate on `data: [*]` and `includes: [*]`.
299
333
 
300
334
  ### Routing constraints
301
335
 
@@ -406,9 +440,11 @@ end
406
440
  ```
407
441
 
408
442
  To avoid polluting the global configuration, you can use `RequestMigrations::Testing`
409
- within your application's `spec/rails_helper.rb` (or similar).
443
+ within your application's `spec/rails_helper.rb`, or a similar spec helper:
410
444
 
411
445
  ```ruby
446
+ require 'request_migrations/testing'
447
+
412
448
  Rspec.configure do |config|
413
449
  config.before :each do
414
450
  RequestMigrations::Testing.setup!
@@ -420,6 +456,9 @@ Rspec.configure do |config|
420
456
  end
421
457
  ```
422
458
 
459
+ This will setup a new test configuration, and then restore the previous global configuration
460
+ after each spec.
461
+
423
462
  ## Tips and tricks
424
463
 
425
464
  Over the years, we're learned a thing or two about versioning an API. We'll share tips here.
@@ -502,7 +541,7 @@ end
502
541
  And for a response containing a collection of users:
503
542
 
504
543
  ```ruby
505
- class CombineNamesForUserMigration < RequestMigrations::Migration
544
+ class CombineNamesForUsersMigration < RequestMigrations::Migration
506
545
  description %(transforms a collection of users' first and last names to a combined name attribute)
507
546
 
508
547
  migrate if: -> data { data in [*, { type: 'user' }, *] do |data|
@@ -603,7 +642,7 @@ end
603
642
 
604
643
  Avoid using routing version constraints that remove functionality. They can be a headache
605
644
  during upgrades. Consider only making _additive_ changes. Instead, consider removing or
606
- hiding the documenation for old or deprecated endpoints, to limit any new usage.
645
+ hiding the documentation for old or deprecated endpoints, to limit any new usage.
607
646
 
608
647
  ```ruby
609
648
  Rails.application.routes.draw do
@@ -680,6 +719,13 @@ to get the data we need in order to complete the migration.
680
719
 
681
720
  Have a tip of your own? Open a pull request!
682
721
 
722
+ ## Examples
723
+
724
+ Below are some real-world examples of request migrations:
725
+
726
+ - Migrations: https://github.com/keygen-sh/keygen-api/tree/master/app/migrations
727
+ - Tests: https://github.com/keygen-sh/keygen-api/tree/master/spec/migrations
728
+
683
729
  ## Is it any good?
684
730
 
685
731
  Yes.
data/SECURITY.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Security Policy
2
2
 
3
- ## Reporting a Vulnerability
3
+ ## Reporting a vulnerability
4
4
 
5
5
  If you find a vulnerability in `request_migrations`, please contact Keygen via
6
- [email](mailto:security@keygen.sh). You will be given public credit for your
7
- disclosure.
6
+ [email](mailto:security@keygen.sh).
7
+
8
+ You will be given public credit for your disclosure.
@@ -2,37 +2,40 @@
2
2
 
3
3
  module RequestMigrations
4
4
  class Configuration
5
- include ActiveSupport::Configurable
6
-
7
5
  ##
8
6
  # logger defines the logger used by request_migrations.
9
7
  #
10
8
  # @return [Logger] the logger.
11
- config_accessor(:logger) { Logger.new("/dev/null") }
9
+ class_attribute :logger
10
+ self.logger = Logger.new("/dev/null")
12
11
 
13
12
  ##
14
13
  # request_version_resolver defines how request_migrations should resolve the
15
14
  # current version of a request.
16
15
  #
17
16
  # @return [Proc] the request version resolver.
18
- config_accessor(:request_version_resolver) { -> req { self.current_version } }
17
+ class_attribute :request_version_resolver
18
+ self.request_version_resolver = -> req { self.current_version }
19
19
 
20
20
  ##
21
21
  # version_format defines the version format.
22
22
  #
23
23
  # @return [Symbol] format
24
- config_accessor(:version_format) { :semver }
24
+ class_attribute :version_format
25
+ self.version_format = :semver
25
26
 
26
27
  ##
27
28
  # current_version defines the latest version.
28
29
  #
29
30
  # @return [String, Integer, Float, nil] the current version.
30
- config_accessor(:current_version) { nil }
31
+ class_attribute :current_version
32
+ self.current_version = nil
31
33
 
32
34
  ##
33
35
  # versions defines past versions and their migrations.
34
36
  #
35
37
  # @return [Hash<String, Array<Symbol, String, Class>>] past versions.
36
- config_accessor(:versions) { {} }
38
+ class_attribute :versions
39
+ self.versions = {}
37
40
  end
38
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RequestMigrations
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.2"
5
5
  end
@@ -9,10 +9,7 @@ module RequestMigrations
9
9
  def self.setup!
10
10
  @@config = RequestMigrations.config
11
11
 
12
- RequestMigrations.reset!
13
- RequestMigrations.configure do |config|
14
- @@config.config.each { |(k, v)| config.config[k] = v }
15
- end
12
+ RequestMigrations.config = @@config.dup
16
13
  end
17
14
 
18
15
  ##
@@ -46,13 +46,10 @@ module RequestMigrations
46
46
  ##
47
47
  # @private
48
48
  def self.config=(cfg)
49
- @config = cfg
50
- end
49
+ raise ArgumentError, 'invalid config provided' unless
50
+ cfg.is_a?(Configuration)
51
51
 
52
- ##
53
- # @private
54
- def self.reset!
55
- @config = RequestMigrations::Configuration.new
52
+ @config = cfg
56
53
  end
57
54
 
58
55
  ##
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2025-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,7 +80,7 @@ homepage: https://github.com/keygen-sh/request_migrations
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}
83
- post_install_message:
83
+ post_install_message:
84
84
  rdoc_options: []
85
85
  require_paths:
86
86
  - lib
@@ -88,15 +88,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: '3.0'
91
+ version: '3.1'
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.3.7
99
- signing_key:
98
+ rubygems_version: 3.5.11
99
+ signing_key:
100
100
  specification_version: 4
101
101
  summary: Write request and response migrations for your Ruby on Rails API.
102
102
  test_files: []