### Install Rails AppVersion and Generate Configuration Files Source: https://github.com/seuros/rails_app_version/blob/master/README.md After adding the gem to the Gemfile, execute these commands to install dependencies, copy the default configuration file, and create an initial `VERSION` file. This sets up the basic structure for version management within your Rails application. ```bash $ bundle install $ rails app:version:config # Copies the default configuration file $ echo "1.0.0" > VERSION # Create initial version file ``` -------------------------------- ### Customize Rails AppVersion Configuration for Environments Source: https://github.com/seuros/rails_app_version/blob/master/README.md This example demonstrates how to customize `config/app_version.yml` for different environments. While hardcoding the version is not recommended, this shows how to set environment-specific values like `environment` and `show_revision` for development and staging. ```yaml shared: # Not recommended: hardcoding version in YAML version: '1.2.3' environment: production development: environment: local show_revision: true staging: environment: staging ``` -------------------------------- ### Rails Console Version and Environment Display Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet shows the output displayed when starting a Rails console with the RailsAppVersion gem integrated. It automatically provides key information such as Ruby version, application environment, and application version, streamlining debugging and verification processes for developers. ```text Welcome to the Rails console! Ruby version: 3.2.0 Application environment: staging Application version: 1.2.3 To exit, press `Ctrl + D`. ``` -------------------------------- ### Manually Configure Rails AppVersion Middleware Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet provides an example of how to manually add the Rails AppVersion middleware in your application configuration, typically in `config/application.rb` or an environment-specific file. This offers an alternative to YAML configuration for more granular control over middleware options. ```ruby # config/application.rb or config/environments/*.rb config.middleware.use RailsAppVersion::Middleware, version_header: 'X-App-Version', environment_header: 'X-App-Environment' ``` -------------------------------- ### Access Rails Application Version Information Source: https://github.com/seuros/rails_app_version/blob/master/README.md This Ruby snippet illustrates various ways to access version details using `Rails.application.version`. It shows how to get the full version string, individual components (major, minor, patch), check status (production_ready?, prerelease?), and obtain a cache-friendly key. ```ruby # Get the current version Rails.application.version.to_s # => "1.2.3" # Check version components Rails.application.version.major # => 1 Rails.application.version.minor # => 2 Rails.application.version.patch # => 3 # Check version status Rails.application.version.production_ready? # => true Rails.application.version.prerelease? # => false # Get a cache-friendly version string Rails.application.version.to_cache_key # => "1-2-3" ``` -------------------------------- ### Add Rails AppVersion Gem to Gemfile Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet shows the line to add to your application's Gemfile to include the Rails AppVersion gem. This is the essential first step in installing the gem and making its functionalities available in your Rails project. ```ruby gem "rails_app_version" ``` -------------------------------- ### Manage Asset and Page Caching with Rails AppVersion Source: https://github.com/seuros/rails_app_version/blob/master/README.md This example shows two ways to use Rails AppVersion for cache management. The first demonstrates cache busting assets using `to_cache_key` in an `AssetManifest` class. The second illustrates how to use the version as part of a cache key for page caching in a controller, ensuring cache invalidation on version changes. ```ruby class AssetManifest def asset_path(path) "/assets/#{path}?v=#{Rails.application.version.to_cache_key}" end end # Or in your controller def index Rails.cache.fetch("index-page#{Rails.application.version.to_cache_key}") do render :index end end ``` -------------------------------- ### Define Application Version in VERSION File Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet illustrates the recommended way to manage your application's version: by creating a `VERSION` file in the root directory containing only the version number. This method promotes clear version history, easy automated updates during deployment, and compatibility with CI/CD pipelines. ```plaintext 1.2.3 ``` -------------------------------- ### Configure RailsAppVersion Middleware Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet demonstrates how to configure the RailsAppVersion middleware in `config/application.rb` or environment-specific files. It shows how to customize the HTTP header names used for version and environment information, allowing for flexible integration into existing systems. ```ruby config.middleware.use RailsAppVersion::AppInfoMiddleware, { version_header: 'X-Custom-Version', environment_header: 'X-Custom-Environment' } ``` -------------------------------- ### Manage Rails Application Environment Source: https://github.com/seuros/rails_app_version/blob/master/README.md This Ruby snippet illustrates how to access the current Rails application environment and perform environment-specific checks using the `Rails.application.env` object. It provides a convenient way to determine the active environment (e.g., 'staging', 'production') and execute conditional logic based on it. ```ruby # Get the current environment Rails.application.env # => "staging" # Environment checks Rails.application.env.production? # => false Rails.application.env.staging? # => true ``` -------------------------------- ### Default Rails AppVersion Configuration in YAML Source: https://github.com/seuros/rails_app_version/blob/master/README.md This YAML snippet shows the default `config/app_version.yml` file. It demonstrates how the gem attempts to read version and revision from `VERSION` and `REVISION` files, falling back to defaults if not found. It also configures environment and revision visibility based on the Rails environment. ```yaml shared: # Attempts to read from VERSION file, falls back to '0.0.0' version: <%= Rails.root.join('VERSION').read.strip rescue '0.0.0' %> # Attempts to read from REVISION file, then tries git commit hash, finally falls back to '0' revision: <%= Rails.root.join('REVISION').read.strip rescue (`git rev-parse HEAD`.strip rescue '0') %> show_revision: <%= Rails.env.local? %> environment: <%= ENV.fetch('RAILS_APP_ENV', Rails.env) %> ``` -------------------------------- ### Configure Rails AppVersion Middleware in YAML Source: https://github.com/seuros/rails_app_version/blob/master/README.md This YAML configuration snippet shows how to enable and customize the optional version headers middleware in `config/app_version.yml`. It demonstrates enabling the middleware for the `staging` environment and setting custom header names, while disabling it for `development`. ```yaml development: middleware: enabled: false staging: middleware: enabled: true options: version_header: X-Staging-Version environment_header: X-Staging-Environment ``` -------------------------------- ### Integrate Rails AppVersion with Sentry for Error Reporting Source: https://github.com/seuros/rails_app_version/blob/master/README.md This snippet demonstrates how to configure Sentry to use Rails AppVersion's exposed version and environment information. It sets the Sentry release to the application's version string and the environment to the application's environment, providing crucial context for error tracking. ```ruby Sentry.init do |config| config.release = Rails.application.version.to_s config.environment = Rails.application.env end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.