rails_action_deprecation 0.1.0 → 0.2.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 +4 -4
- data/CHANGES.md +4 -0
- data/README.md +44 -5
- data/lib/rails_action_deprecation/controller.rb +17 -6
- data/lib/rails_action_deprecation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccae3581cfc634686eb8f0a9b21309db739dff0f3e7b8b55a3667d0e2efd5abc
|
4
|
+
data.tar.gz: 525195bebf4b792f3819593bc1feb0390cd3c330ae90c26d710f59dd64548b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10767b6b4b23e8a294e6c27b88b5f804ac4bee8a9cbe38f6587c03c7e79c1b22e356beb084dd29e3346a07f18c6e8e886e4117df35e6bd421f306df2febf89c5
|
7
|
+
data.tar.gz: 78124ba4a85f6b869e8f500e119dffd2d238e24217865bf105d095a76bd4f1053dc588d05fde3b38cc824345a1cb71e1387939d5344db2e9a31605a213ca02b8
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -31,19 +31,58 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
## Usage
|
33
33
|
|
34
|
-
To enable deprecation and sunset in your controller, simply use the provided `deprecate_endpoint` and `sunset_endpoint` functions.
|
34
|
+
To enable deprecation and sunset in your controller, simply use the provided `deprecate_endpoint` and `sunset_endpoint` functions.
|
35
|
+
These register an `after_action` hook that sets the relevant HTTP headers and outputs a message via `ActiveSupport::Deprecation`.
|
35
36
|
|
36
|
-
Both functions take exactly the same parameters.
|
37
|
+
Both functions take exactly the same parameters.
|
38
|
+
The first is a DateTime describing the date of deprecation or sunset.
|
39
|
+
By default the deprecation or sunset is set for any action in the controller.
|
40
|
+
To limit this the `only:` parameter can be used exactly as it is available for the rails controller hooks.
|
41
|
+
|
42
|
+
If you want to make more information available to your users, the `link:` parameter must be specified with a percent encoded URL.
|
43
|
+
This URL will be part of the response's Link HTTP header with the relation `deprecation` or respectively `sunset`.
|
44
|
+
|
45
|
+
Example with deprecated and/or sunset `create` and `destroy` actions:
|
46
|
+
```ruby
|
47
|
+
class ExampleController < ActionController::Base
|
48
|
+
deprecate_endpoint DateTime.new(2022, 07, 01, 12, 34, 56), only: [:create]
|
49
|
+
deprecate_endpoint DateTime.new(2022, 07, 01, 12, 34, 56), only: [:destroy], link: "https://github.com/Qurasoft"
|
50
|
+
sunset_endpoint DateTime.new(2023, 07, 01), only: [:destroy]
|
51
|
+
|
52
|
+
def index
|
53
|
+
render json: ['element1', 'element2']
|
54
|
+
end
|
55
|
+
|
56
|
+
def show
|
57
|
+
render json: 'element1'
|
58
|
+
end
|
59
|
+
|
60
|
+
def create
|
61
|
+
render json: 'newElement'
|
62
|
+
end
|
63
|
+
|
64
|
+
def update
|
65
|
+
render json: 'changedElement'
|
66
|
+
end
|
67
|
+
|
68
|
+
def destroy
|
69
|
+
head :no_content
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
37
73
|
|
38
74
|
## Development
|
39
75
|
|
40
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
77
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
78
|
|
42
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
80
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
81
|
|
44
82
|
## Contributing
|
45
83
|
|
46
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/qurasoft/rails_action_deprecation.
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/qurasoft/rails_action_deprecation.
|
85
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
47
86
|
|
48
87
|
## License
|
49
88
|
|
@@ -3,21 +3,21 @@ module RailsActionDeprecation
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
def deprecate_endpoint(datetime, only: nil)
|
6
|
+
def deprecate_endpoint(datetime, only: nil, link: nil)
|
7
7
|
# Deliver the (draft) Deprecation HTTP header with the response
|
8
8
|
# https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-deprecation-header
|
9
|
-
deprecation 'Deprecation', datetime, only: only
|
9
|
+
deprecation 'Deprecation', datetime, only: only, link: link
|
10
10
|
end
|
11
11
|
|
12
|
-
def sunset_endpoint(datetime, only: nil)
|
12
|
+
def sunset_endpoint(datetime, only: nil, link: nil)
|
13
13
|
# Deliver the Sunset HTTP header with the response
|
14
14
|
# https://datatracker.ietf.org/doc/html/rfc8594
|
15
|
-
deprecation 'Sunset', datetime, only: only
|
15
|
+
deprecation 'Sunset', datetime, only: only, link: link
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
19
19
|
|
20
|
-
def deprecation(header, datetime, only: nil)
|
20
|
+
def deprecation(header, datetime, only: nil, link: nil)
|
21
21
|
after_action(only: only) do |controller|
|
22
22
|
klass = controller.class
|
23
23
|
user_agent = request.headers['User-Agent']
|
@@ -25,7 +25,18 @@ module RailsActionDeprecation
|
|
25
25
|
# Log the deprecation
|
26
26
|
ActiveSupport::Deprecation.warn("#{klass}##{method} deprecated endpoint (#{header.downcase} date #{datetime.iso8601}) has been called by #{user_agent}")
|
27
27
|
|
28
|
-
response.
|
28
|
+
response.set_header header, datetime.httpdate
|
29
|
+
|
30
|
+
# Add a Link header with the correct relation if specified
|
31
|
+
if link.present?
|
32
|
+
link_header = "<#{link}>; rel=\"#{header.downcase}\""
|
33
|
+
# Append if a Link header is already present
|
34
|
+
if response.has_header? "Link"
|
35
|
+
response.set_header "Link", "#{response.get_header("Link")}, #{link_header}"
|
36
|
+
else
|
37
|
+
response.set_header "Link", link_header
|
38
|
+
end
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_action_deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Keune
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|