rails_app_version 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ceff4b502902ed60d708fd295202078d48fc55a56abbd427b92daed2c5da7ad
4
- data.tar.gz: f517710e94b7d97c4e90593f3ca6f9ab9b2351848d3fdb1e2ead54e91aee59a7
3
+ metadata.gz: f0113f2ae9ce34c5fcbb45f7d55c02345cba3783b2ea2591006bd373191b48ea
4
+ data.tar.gz: 3892b19123b2c479f92a3479f4bcc17ce5a96aa146e9cae8997cd8d1d36ef31f
5
5
  SHA512:
6
- metadata.gz: 656786a178a739b22a45d8e1ec71e013c4dfd121e979726dd9536ff6c90630cfb0152b6585f0b081acdd1eab584a760db21388ff278c490d4c86620ebecd1b95
7
- data.tar.gz: e124ff8fb6fdc72478947a215e41865cb93bbb1c08607f74a5d7fffd9f4776964e9566433ac812eecb8a6a187f5288114ff67263dc4f144b5d1284a4c3db2e8a
6
+ metadata.gz: 927b60eb8ddeae0e19ece3f442cc81fb09a68e879f96a5e9cb70a487215432c9324fd1c938ea81ae062d77001901af9755bf9649ed60d77fc87f2c6d5285196a
7
+ data.tar.gz: e71614418c799ad88bfb4039463070a2e025d11baf47c68e29e51ffcba0b7ff4a329630cc8018579e95ff2ee651ba7ef6bacb8024f5061e4d5bd981009a2825f
data/README.md CHANGED
@@ -33,6 +33,14 @@ class AssetManifest
33
33
  "/assets/#{path}?v=#{Rails.application.version.to_cache_key}"
34
34
  end
35
35
  end
36
+
37
+ # Or in your controller
38
+
39
+ def index
40
+ Rails.cache.fetch("index-page#{Rails.application.version.to_cache_key}") do
41
+ render :index
42
+ end
43
+ end
36
44
  ```
37
45
 
38
46
  ## Installation
@@ -48,7 +56,7 @@ Then execute:
48
56
  ```bash
49
57
  $ bundle install
50
58
  $ rails app:version:config # Copies the default configuration file
51
- $ echo "1.0.0" > VERSION # Create initial version file
59
+ $ echo "1.0.0" > VERSION # Create initial version file
52
60
  ```
53
61
 
54
62
  ## Version Management
@@ -61,7 +69,6 @@ The recommended approach is to maintain a `VERSION` file in your application's r
61
69
  only the version number:
62
70
 
63
71
  ```plaintext
64
- # VERSION
65
72
  1.2.3
66
73
  ```
67
74
 
@@ -128,7 +135,7 @@ Rails.application.version.to_cache_key # => "1-2-3"
128
135
  ## Version Headers Middleware
129
136
 
130
137
  Rails AppVersion includes an optional middleware that adds version and environment information to HTTP response headers.
131
- This is particularly useful in staging and development environments to verify deployment success and track which version
138
+ This is particularly useful in staging and pre-production environments to verify deployment success and track which version
132
139
  of the application is serving requests.
133
140
 
134
141
  ### Configuring the Middleware
@@ -138,12 +145,7 @@ Enable and configure the middleware in your `config/app_version.yml`:
138
145
  ```yaml
139
146
  development:
140
147
  middleware:
141
- enabled: true
142
- options:
143
- include_revision: true # Include git revision in headers
144
- version_header: X-App-Version
145
- environment_header: X-App-Environment
146
- revision_header: X-App-Revision
148
+ enabled: false
147
149
 
148
150
  staging:
149
151
  middleware:
@@ -161,8 +163,7 @@ You can also add the middleware manually in your application configuration:
161
163
  # config/application.rb or config/environments/staging.rb
162
164
  config.middleware.use RailsAppVersion::AppInfoMiddleware, {
163
165
  version_header: 'X-Custom-Version',
164
- environment_header: 'X-Custom-Environment',
165
- include_revision: true
166
+ environment_header: 'X-Custom-Environment'
166
167
  }
167
168
  ```
168
169
 
@@ -171,7 +172,7 @@ The middleware will add the following headers to each response:
171
172
  - X-App-Version: Current application version, optionally including revision (e.g., "1.2.3" or "1.2.3 (abc123de)")
172
173
  - X-App-Environment: Current environment (e.g., "staging")
173
174
 
174
- When `include_revision` is enabled, the version header will include the first 8 characters of the git revision in
175
+ When `show_revision` is enabled, the version header will include the first 8 characters of the git revision in
175
176
  parentheses. This provides a quick way to verify both the version and the specific deployment in a single header.
176
177
 
177
178
  This makes it easy for developers to verify which version is deployed and running in each environment, particularly
@@ -211,39 +212,6 @@ Rails AppVersion supports several version formats:
211
212
  Version strings are parsed according to Semantic Versioning principles and maintain compatibility with `Gem::Version`
212
213
  for comparison operations.
213
214
 
214
- ## Version Headers
215
-
216
- Enable version headers in HTTP responses to verify deployments and track running versions:
217
-
218
- ```yaml
219
- # config/app_version.yml
220
- development:
221
- middleware:
222
- enabled: true
223
- options:
224
- include_revision: true
225
-
226
- staging:
227
- middleware:
228
- enabled: true
229
- ```
230
-
231
- Or add the middleware manually:
232
-
233
- ```ruby
234
- # config/application.rb
235
- config.middleware.use RailsAppVersion::AppInfoMiddleware, {
236
- version_header: 'X-App-Version',
237
- environment_header: 'X-App-Environment',
238
- include_revision: true
239
- }
240
- ```
241
-
242
- Headers added:
243
-
244
- - X-App-Version: "1.2.3" (or "1.2.3 (abc123de)" with revision)
245
- - X-App-Environment: "production"
246
-
247
215
  ## Contributing
248
216
 
249
217
  We welcome contributions! Here's how you can help:
@@ -3,3 +3,8 @@ shared:
3
3
  revision: <%= Rails.root.join('REVISION').read.strip rescue (`git rev-parse HEAD`.strip rescue '0') %>
4
4
  show_revision: <%= Rails.env.local? %>
5
5
  environment: <%= ENV.fetch('RAILS_APP_ENV', Rails.env) %>
6
+ middleware:
7
+ enabled: true
8
+ options:
9
+ version_header: X-App-Version
10
+ environment_header: X-App-Environment
@@ -4,22 +4,23 @@ module RailsAppVersion
4
4
  class AppInfoMiddleware
5
5
  DEFAULT_OPTIONS = {
6
6
  version_header: "X-App-Version",
7
- environment_header: "X-App-Environment",
8
- revision_header: "X-App-Revision",
9
- include_revision: false
7
+ environment_header: "X-App-Environment"
10
8
  }.freeze
11
9
 
12
10
  def initialize(app, options = {})
13
- @app = app
14
11
  @options = DEFAULT_OPTIONS.merge(options)
12
+ @app = app
15
13
  end
16
14
 
17
15
  def call(env)
16
+ # Call the next middleware in the chain first
18
17
  status, headers, response = @app.call(env)
19
18
 
19
+ # Add our custom headers to the response
20
20
  headers[@options[:version_header]] = Rails.application.version.full
21
21
  headers[@options[:environment_header]] = Rails.application.env
22
22
 
23
+ # Return the modified response
23
24
  [ status, headers, response ]
24
25
  end
25
26
  end
@@ -45,9 +45,16 @@ module RailsAppVersion
45
45
  all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
46
46
  all_configs[:shared]
47
47
  end
48
-
49
48
  @version = RailsAppVersion::Version.create(@app_config[:version], @app_config[:revision])
50
49
  @env = ActiveSupport::StringInquirer.new(@app_config.fetch(:environment, Rails.env))
51
50
  end
51
+
52
+ initializer "middleware" do |app|
53
+ # Add the middleware to the stack if enabled
54
+ if @app_config.dig(:middleware, :enabled)
55
+ options = @app_config.dig(:middleware, :options) || {}
56
+ app.middleware.insert_before Rails::Rack::Logger, RailsAppVersion::AppInfoMiddleware, **options
57
+ end
58
+ end
52
59
  end
53
60
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppVersion
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
 
6
6
  class Version < Gem::Version
7
7
  attr_reader :major, :minor, :patch, :pre, :revision
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_app_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-23 00:00:00.000000000 Z
10
+ date: 2024-12-31 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: railties
@@ -81,7 +80,6 @@ metadata:
81
80
  source_code_uri: https://github.com/seuros/rails_app_version
82
81
  changelog_uri: https://github.com/seuros/rails_app_version/blob/master/CHANGELOG.md
83
82
  rubygems_mfa_required: 'true'
84
- post_install_message:
85
83
  rdoc_options: []
86
84
  require_paths:
87
85
  - lib
@@ -96,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
94
  - !ruby/object:Gem::Version
97
95
  version: '0'
98
96
  requirements: []
99
- rubygems_version: 3.5.22
100
- signing_key:
97
+ rubygems_version: 3.6.2
101
98
  specification_version: 4
102
99
  summary: Get the version of your Rails app
103
100
  test_files: []