Rack::AppVersion
is a middleware that sets the version of an app (Rack compatible web applications) via response header.
gem 'rack-app_version'
module YourApp
class Application < Rails::Application
# ...
config.middleware.use Rack::AppVersion
end
end
module Rack
class AppVersion
def self.generate_version
# Implement logic of getting application version here.
end
end
end
require 'rack/app_version/rake_task'
Rack::AppVersion.load_tasks
Doing bundle exec rake -T | grep app_version
will give you the following which you can use:
rake app_version:generate # generate app version and write it in .app_version file
rake app_version:init # generate .app_version file that will contain application version
This rspec matcher can be used by the application to ensure that everything is properly configured.
it 'has app version in response headers' do
expect(env).to have_app_version
end
To determine where to put the Rack::AppVersion
middleware in the Rack stack, run the following command:
bundle exec rake middleware
In many cases, the Rack stack will be different running in production environment. Run the following command to see the middleware stack in production:
RAILS_ENV=production bundle exec rake middleware
See The Rails Guide to Rack for more details on rack middlewares or watch the railscast.