rails_location_header 1.0.0 → 1.0.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 +4 -4
- data/.rubocop.yml +309 -4
- data/CHANGELOG.md +41 -1
- data/README.md +12 -2
- data/lib/rails_location_header/controller_extension.rb +6 -6
- data/lib/rails_location_header/railtie.rb +1 -1
- data/lib/rails_location_header/version.rb +1 -1
- data/lib/rails_location_header.rb +4 -4
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3998d156e632dbba5a1bdc4b5d418ff51dab1d93d4f29e72c244d8d0f76e9a46
|
4
|
+
data.tar.gz: 732d121b2e044c68595f505e6056977250fda8f16ca6dfc681b72aafe5d9e2c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80bfbc95b3893e7125faaf292c11d0d61f390f66b615c2dea30278c8ebb91a16493ad51889cb22b8f8660e461534346ab45601f40f9add1210d0bf79178b0f43
|
7
|
+
data.tar.gz: 1586bd510a084e6c00caef89ce24fce0d05e0199408428f407da953afb8d297c18db05ed1aee9780c062dabde1308643d659ba7ea37ae09aa1ea03f2fb7283bc
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,313 @@
|
|
1
|
+
plugins:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
inherit_mode:
|
5
|
+
merge:
|
6
|
+
- Exclude
|
7
|
+
|
1
8
|
AllCops:
|
2
|
-
|
9
|
+
NewCops: enable
|
10
|
+
SuggestExtensions: false
|
11
|
+
Exclude:
|
12
|
+
- "data/**/*"
|
13
|
+
- "db/**/*"
|
14
|
+
|
15
|
+
# All cops except your using extensions are disabled by default.
|
16
|
+
Bundler:
|
17
|
+
Enabled: false
|
18
|
+
Gemspec:
|
19
|
+
Enabled: false
|
20
|
+
Layout:
|
21
|
+
Enabled: false
|
22
|
+
Lint:
|
23
|
+
Enabled: false
|
24
|
+
Metrics:
|
25
|
+
Enabled: false
|
26
|
+
Naming:
|
27
|
+
Enabled: false
|
28
|
+
Performance:
|
29
|
+
Enabled: false
|
30
|
+
Exclude:
|
31
|
+
- "test/**/*"
|
32
|
+
- "spec/**/*"
|
33
|
+
Security:
|
34
|
+
Enabled: false
|
35
|
+
Style:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
# Align `when` with `end`.
|
39
|
+
Layout/CaseIndentation:
|
40
|
+
Enabled: true
|
41
|
+
EnforcedStyle: end
|
42
|
+
|
43
|
+
# Align comments with method definitions.
|
44
|
+
Layout/CommentIndentation:
|
45
|
+
Enabled: true
|
46
|
+
|
47
|
+
Layout/ElseAlignment:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
Layout/EmptyLineAfterMagicComment:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Layout/EmptyLinesAroundBlockBody:
|
54
|
+
Enabled: true
|
55
|
+
|
56
|
+
# In a regular class definition, no empty lines around the body.
|
57
|
+
Layout/EmptyLinesAroundClassBody:
|
58
|
+
Enabled: true
|
59
|
+
|
60
|
+
# In a regular method definition, no empty lines around the body.
|
61
|
+
Layout/EmptyLinesAroundMethodBody:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
# In a regular module definition, no empty lines around the body.
|
65
|
+
Layout/EmptyLinesAroundModuleBody:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
# Align `end` with the matching keyword or starting expression except for
|
69
|
+
# assignments, where it should be aligned with the LHS.
|
70
|
+
Layout/EndAlignment:
|
71
|
+
Enabled: true
|
72
|
+
EnforcedStyleAlignWith: variable
|
73
|
+
|
74
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
75
|
+
# extra level of indentation.
|
76
|
+
#
|
77
|
+
# We break this rule in context, though, e.g. for private-only concerns,
|
78
|
+
# so we leave it disabled.
|
79
|
+
Layout/IndentationConsistency:
|
80
|
+
Enabled: false
|
81
|
+
EnforcedStyle: indented_internal_methods
|
82
|
+
|
83
|
+
# Detect hard tabs, no hard tabs.
|
84
|
+
Layout/IndentationStyle:
|
85
|
+
Enabled: true
|
86
|
+
|
87
|
+
# Two spaces, no tabs (for indentation).
|
88
|
+
#
|
89
|
+
# Doesn't behave properly with private-only concerns, so it's disabled.
|
90
|
+
Layout/IndentationWidth:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Layout/LeadingCommentSpace:
|
94
|
+
Enabled: true
|
95
|
+
|
96
|
+
Layout/SpaceAfterColon:
|
97
|
+
Enabled: true
|
98
|
+
|
99
|
+
Layout/SpaceAfterComma:
|
100
|
+
Enabled: true
|
101
|
+
|
102
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
Layout/SpaceAroundKeyword:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Use `foo {}` not `foo{}`.
|
109
|
+
Layout/SpaceBeforeBlockBraces:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Layout/SpaceBeforeComma:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Layout/SpaceBeforeFirstArg:
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
# Use `[ a, [ b, c ] ]` not `[a, [b, c]]`
|
119
|
+
# Use `[]` not `[ ]`
|
120
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
121
|
+
Enabled: true
|
122
|
+
EnforcedStyle: no_space
|
123
|
+
EnforcedStyleForEmptyBrackets: no_space
|
124
|
+
|
125
|
+
# Use `%w[ a b ]` not `%w[ a b ]`.
|
126
|
+
Layout/SpaceInsideArrayPercentLiteral:
|
127
|
+
Enabled: true
|
128
|
+
|
129
|
+
# Use `foo { bar }` not `foo {bar}`.
|
130
|
+
# Use `foo { }` not `foo {}`.
|
131
|
+
Layout/SpaceInsideBlockBraces:
|
132
|
+
Enabled: true
|
133
|
+
EnforcedStyleForEmptyBraces: space
|
134
|
+
|
135
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
136
|
+
# Use `{}` not `{ }`.
|
137
|
+
Layout/SpaceInsideHashLiteralBraces:
|
138
|
+
Enabled: true
|
139
|
+
EnforcedStyle: space
|
140
|
+
EnforcedStyleForEmptyBraces: no_space
|
141
|
+
|
142
|
+
# Use `foo(bar)` not `foo( bar )`
|
143
|
+
Layout/SpaceInsideParens:
|
144
|
+
Enabled: true
|
145
|
+
|
146
|
+
# Requiring a space is not yet supported as of 0.59.2
|
147
|
+
# Use `%w[ foo ]` not `%w[foo]`
|
148
|
+
Layout/SpaceInsidePercentLiteralDelimiters:
|
149
|
+
Enabled: false
|
150
|
+
#EnforcedStyle: space
|
151
|
+
|
152
|
+
# Use `hash[:key]` not `hash[ :key ]`
|
153
|
+
Layout/SpaceInsideReferenceBrackets:
|
154
|
+
Enabled: true
|
155
|
+
|
156
|
+
# Blank lines should not have any spaces.
|
157
|
+
Layout/TrailingEmptyLines:
|
158
|
+
Enabled: true
|
3
159
|
|
160
|
+
# No trailing whitespace.
|
161
|
+
Layout/TrailingWhitespace:
|
162
|
+
Enabled: true
|
163
|
+
|
164
|
+
Lint/RedundantStringCoercion:
|
165
|
+
Enabled: true
|
166
|
+
|
167
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
168
|
+
Lint/RequireParentheses:
|
169
|
+
Enabled: true
|
170
|
+
|
171
|
+
Lint/UriEscapeUnescape:
|
172
|
+
Enabled: true
|
173
|
+
|
174
|
+
Performance/FlatMap:
|
175
|
+
Enabled: true
|
176
|
+
|
177
|
+
# We generally prefer &&/|| but like low-precedence and/or in context
|
178
|
+
Style/AndOr:
|
179
|
+
Enabled: false
|
180
|
+
|
181
|
+
# Prefer Foo.method over Foo::method
|
182
|
+
Style/ColonMethodCall:
|
183
|
+
Enabled: true
|
184
|
+
|
185
|
+
Style/DefWithParentheses:
|
186
|
+
Enabled: true
|
187
|
+
|
188
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
189
|
+
Style/HashSyntax:
|
190
|
+
Enabled: true
|
191
|
+
EnforcedShorthandSyntax: either
|
192
|
+
|
193
|
+
# Defining a method with parameters needs parentheses.
|
194
|
+
Style/MethodDefParentheses:
|
195
|
+
Enabled: true
|
196
|
+
|
197
|
+
Style/ParenthesesAroundCondition:
|
198
|
+
Enabled: true
|
199
|
+
|
200
|
+
Style/PercentLiteralDelimiters:
|
201
|
+
Enabled: true
|
202
|
+
PreferredDelimiters:
|
203
|
+
default: "()"
|
204
|
+
"%i": "[]"
|
205
|
+
"%I": "[]"
|
206
|
+
"%r": "{}"
|
207
|
+
"%w": "[]"
|
208
|
+
"%W": "[]"
|
209
|
+
|
210
|
+
# Use quotes for string literals when they are enough.
|
211
|
+
Style/RedundantPercentQ:
|
212
|
+
Enabled: false
|
213
|
+
|
214
|
+
Style/RedundantReturn:
|
215
|
+
Enabled: true
|
216
|
+
AllowMultipleReturnValues: false
|
217
|
+
|
218
|
+
Style/Semicolon:
|
219
|
+
Enabled: true
|
220
|
+
AllowAsExpressionSeparator: true
|
221
|
+
|
222
|
+
Style/StabbyLambdaParentheses:
|
223
|
+
Enabled: true
|
224
|
+
|
225
|
+
# Use `"foo"` not `'foo'` unless escaping is required
|
4
226
|
Style/StringLiterals:
|
5
|
-
|
227
|
+
Enabled: true
|
228
|
+
EnforcedStyle: single_quotes
|
229
|
+
Include:
|
230
|
+
- "app/**/*"
|
231
|
+
- "config/**/*"
|
232
|
+
- "lib/**/*"
|
233
|
+
- "test/**/*"
|
234
|
+
- "spec/**/*"
|
235
|
+
- "Gemfile"
|
236
|
+
|
237
|
+
Style/TrailingCommaInArrayLiteral:
|
238
|
+
Enabled: true
|
239
|
+
|
240
|
+
Style/TrailingCommaInHashLiteral:
|
241
|
+
Enabled: true
|
242
|
+
|
243
|
+
Layout/EmptyLinesAroundAccessModifier:
|
244
|
+
Enabled: true
|
245
|
+
|
246
|
+
Layout/EmptyLineBetweenDefs:
|
247
|
+
Enabled: true
|
248
|
+
|
249
|
+
Layout/LineLength:
|
250
|
+
Enabled: true
|
251
|
+
Exclude:
|
252
|
+
- "db/**/*"
|
253
|
+
- "config/routes.rb"
|
254
|
+
- "bin/**/*"
|
255
|
+
|
256
|
+
Metrics/AbcSize:
|
257
|
+
Enabled: true
|
258
|
+
Max: 17
|
259
|
+
Exclude:
|
260
|
+
- "db/**/*"
|
261
|
+
- "config/routes.rb"
|
262
|
+
- "bin/**/*"
|
263
|
+
|
264
|
+
Metrics/BlockLength:
|
265
|
+
Enabled: true
|
266
|
+
Exclude:
|
267
|
+
- "db/**/*"
|
268
|
+
- "spec/**/*"
|
269
|
+
- "config/routes.rb"
|
270
|
+
- "bin/**/*"
|
271
|
+
|
272
|
+
Metrics/BlockNesting:
|
273
|
+
Enabled: true
|
274
|
+
Max: 1
|
275
|
+
Exclude:
|
276
|
+
- "db/**/*"
|
277
|
+
- "config/routes.rb"
|
278
|
+
- "bin/**/*"
|
279
|
+
|
280
|
+
Metrics/CyclomaticComplexity:
|
281
|
+
Enabled: true
|
282
|
+
Exclude:
|
283
|
+
- "db/**/*"
|
284
|
+
- "config/routes.rb"
|
285
|
+
- "bin/**/*"
|
286
|
+
|
287
|
+
Metrics/MethodLength:
|
288
|
+
Enabled: true
|
289
|
+
Max: 8
|
290
|
+
Exclude:
|
291
|
+
- "db/**/*"
|
292
|
+
- "config/routes.rb"
|
293
|
+
- "bin/**/*"
|
294
|
+
|
295
|
+
Metrics/PerceivedComplexity:
|
296
|
+
Enabled: true
|
297
|
+
Exclude:
|
298
|
+
- "db/**/*"
|
299
|
+
- "config/routes.rb"
|
300
|
+
- "bin/**/*"
|
301
|
+
|
302
|
+
Style/Documentation:
|
303
|
+
Enabled: false
|
304
|
+
|
305
|
+
Style/FrozenStringLiteralComment:
|
306
|
+
Enabled: false
|
307
|
+
|
308
|
+
Style/MethodCallWithArgsParentheses:
|
309
|
+
Enabled: true
|
310
|
+
EnforcedStyle: omit_parentheses
|
6
311
|
|
7
|
-
|
8
|
-
|
312
|
+
Layout/EmptyLineAfterGuardClause:
|
313
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,44 @@
|
|
1
|
-
## [
|
1
|
+
## [1.0.1] - 2025-03-24
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- Introduced `rubocop-performance` gem for enhanced linting capabilities.
|
6
|
+
- Enabled additional RuboCop cops for improved code quality and consistency.
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
|
10
|
+
- Updated `.rubocop.yml` to include detailed configuration for various cops.
|
11
|
+
- Updated `Gemfile` to use single quotes for consistency.
|
12
|
+
- Updated `Gemfile.lock` to reflect the addition of `rubocop-performance`.
|
13
|
+
- Updated `rails_location_header.gemspec` to improve formatting and readability.
|
14
|
+
- Updated `lib/rails_location_header.rb` and other files to align with RuboCop's style guidelines:
|
15
|
+
- Replaced double quotes with single quotes where applicable.
|
16
|
+
- Adjusted method calls to remove unnecessary parentheses.
|
17
|
+
- Improved formatting for multi-line method calls.
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Fixed minor inconsistencies in the `ControllerExtension` and `Railtie` modules.
|
22
|
+
- Fixed version mismatch in `lib/rails_location_header/version.rb` (updated to `1.0.1`).
|
23
|
+
|
24
|
+
### Removed
|
25
|
+
|
26
|
+
- Removed unnecessary comments and redundant code from `rails_location_header.gemspec`.
|
27
|
+
|
28
|
+
## [1.0.0] - 2025-03-24
|
29
|
+
|
30
|
+
### Added
|
31
|
+
|
32
|
+
- Added `X-Entity-ID` and `Location` headers to `create` actions via `ControllerExtension`.
|
33
|
+
- Introduced `Middleware` class for potential future enhancements.
|
34
|
+
- Integrated `Railtie` to automatically include `ControllerExtension` in Rails controllers.
|
35
|
+
- Updated gemspec with metadata, dependencies, and author information.
|
36
|
+
- Enhanced README with installation, usage, and contribution guidelines.
|
37
|
+
|
38
|
+
### Changed
|
39
|
+
|
40
|
+
- Updated version to `1.0.0` in `version.rb`.
|
41
|
+
- Improved gemspec description and summary.
|
2
42
|
|
3
43
|
## [0.1.0] - 2025-03-24
|
4
44
|
|
data/README.md
CHANGED
@@ -18,12 +18,22 @@ gem install rails_location_header
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
To use this gem, include it in your Rails application. The gem automatically integrates with Rails controllers via a Railtie
|
21
|
+
To use this gem, include it in your Rails application. The gem automatically integrates with Rails controllers via a Railtie and works out of the box.
|
22
|
+
|
23
|
+
### How It Works
|
24
|
+
|
25
|
+
1. **`create` action with a 201 status**: The `create` action must return an HTTP `201 Created` status.
|
26
|
+
2. **Instance variable**: Declare an instance variable in the `create` action that matches the entity name (e.g., `@post` in `PostsController`).
|
27
|
+
3. **`show` action and route**: Ensure the controller has a `show` action and a corresponding route to construct the resource's URL.
|
28
|
+
|
29
|
+
### Headers Added
|
30
|
+
|
31
|
+
When the above requirements are met, the gem automatically adds the following headers to the response:
|
22
32
|
|
23
33
|
- `X-Entity-ID`: The ID of the created resource.
|
24
34
|
- `Location`: The URL of the created resource.
|
25
35
|
|
26
|
-
No additional configuration is
|
36
|
+
No additional configuration is needed.
|
27
37
|
|
28
38
|
## Development
|
29
39
|
|
@@ -11,22 +11,22 @@ module CreatedEntityHeader
|
|
11
11
|
def add_location_header
|
12
12
|
return unless response.status == 201
|
13
13
|
|
14
|
-
created_resource = instance_variable_get
|
15
|
-
return unless created_resource.respond_to?
|
14
|
+
created_resource = instance_variable_get "@#{controller_name.singularize}"
|
15
|
+
return unless created_resource.respond_to? :id
|
16
16
|
|
17
|
-
response.headers[
|
17
|
+
response.headers['X-Entity-ID'] = created_resource.id.to_s
|
18
18
|
|
19
|
-
response.headers[
|
19
|
+
response.headers['Location'] = url_for created_resource
|
20
20
|
end
|
21
21
|
|
22
22
|
def url_for(created_resource)
|
23
23
|
url_helpers = Rails.application.routes.url_helpers
|
24
|
-
url_helpers.url_for
|
24
|
+
url_helpers.url_for \
|
25
25
|
controller: controller_name, action: :show,
|
26
26
|
id: created_resource.id,
|
27
27
|
only_path: false,
|
28
28
|
host: request.host, port: request.port
|
29
|
-
|
29
|
+
|
30
30
|
rescue StandardError => e
|
31
31
|
Rails.logger.warn "[RailsLocationHeader] Could not set Location Header: #{e.message}"
|
32
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module CreatedEntityHeader
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
initializer
|
3
|
+
initializer 'created_entity_header.configure_controller' do
|
4
4
|
ActiveSupport.on_load :action_controller do
|
5
5
|
include CreatedEntityHeader::ControllerExtension
|
6
6
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative 'rails_location_header/version'
|
4
|
+
require 'rails_location_header/railtie' if defined?(Rails)
|
5
|
+
require 'rails_location_header/controller_extension'
|
6
6
|
|
7
7
|
module RailsLocationHeader
|
8
8
|
class Middleware
|
@@ -11,7 +11,7 @@ module RailsLocationHeader
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
-
status, headers, response = @app.call
|
14
|
+
status, headers, response = @app.call env
|
15
15
|
[status, headers, response]
|
16
16
|
end
|
17
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_location_header
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Sebastian Herrera Aguilar
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-
|
10
|
+
date: 2025-04-21 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
@@ -24,8 +23,9 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '6.0'
|
27
|
-
description:
|
28
|
-
when a new record is created
|
26
|
+
description: |-
|
27
|
+
A Rails gem that automatically adds X-Entity-ID and Location headers when a new record is created
|
28
|
+
successfully.
|
29
29
|
email:
|
30
30
|
- esrbastianherrera@gmail.com
|
31
31
|
executables: []
|
@@ -51,7 +51,6 @@ metadata:
|
|
51
51
|
homepage_uri: https://github.com/EliSebastian/rails_location_header
|
52
52
|
source_code_uri: https://github.com/EliSebastian/rails_location_header
|
53
53
|
changelog_uri: https://github.com/EliSebastian/rails_location_header/blob/main/CHANGELOG.md
|
54
|
-
post_install_message:
|
55
54
|
rdoc_options: []
|
56
55
|
require_paths:
|
57
56
|
- lib
|
@@ -66,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
65
|
- !ruby/object:Gem::Version
|
67
66
|
version: '0'
|
68
67
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
70
|
-
signing_key:
|
68
|
+
rubygems_version: 3.6.2
|
71
69
|
specification_version: 4
|
72
70
|
summary: Adds X-Entity-ID and Location headers in create actions.
|
73
71
|
test_files: []
|