Compare your Rails application files with the ones generated by Rails main branch. This helps you keep track of changes between your customized files and the latest Rails templates.
Add this line to your application's Gemfile:
gem 'rails-diff'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install rails-diff
# Compare a single file
rails-diff file Dockerfile
# Compare multiple files
rails-diff file Dockerfile Gemfile
# Force regenerate Rails app by clearing cache
rails-diff file Dockerfile --clear-cache
# Fail if there are differences (useful for CI)
rails-diff file Dockerfile --fail-on-diff
# Compare a specific commit
rails-diff file Dockerfile --commit 7df1b8
# Compare files that would be created by a generator
rails-diff generated authentication
# Compare files with generator arguments
rails-diff generated scaffold Post title:string body:text
# Force regenerate Rails app by clearing cache
rails-diff generated scaffold Post --clear-cache
# Skip specific files or directories during the diff
rails-diff generated scaffold Post --skip app/views app/helpers
# Fail if there are differences (useful for CI)
rails-diff generated scaffold Post --fail-on-diff
# Compare a specific commit
rails-diff generated authentication --commit 7df1b8
If this option is specified, the command will exit with a non-zero status code if there are any differences between your files and the generated ones. This can be particularly useful when using the gem in Continuous Integration (CI) environments.
Specify the commit hash you want to compare against. If not provided, the latest commit on main will be used by default.
Specify additional options to be used with the rails new
command. This allows you to customize the generated Rails application, for example, by specifying a different database.
Example:
rails-diff file Dockerfile --new-app-options="--database=postgresql"
When you run the diff, it will:
- Clone the latest Rails from main branch
- Generate a new Rails app with the same name as yours
- Show you a colored diff between your file and the generated one
The gem caches the generated Rails application to avoid regenerating it on every run. The cache is automatically invalidated when:
- Rails has new commits on main
- The cache directory doesn't exist
You can also force clear the cache by using the --no-cache
option (or its alias --clear-cache
) with any command.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
.
Bug reports and pull requests are welcome on GitHub at /~https://github.com/matheusrich/rails-diff.
The gem is available as open source under the terms of the MIT License.