Skip to content

Compare Rails-generated files with the ones in your repository

License

Notifications You must be signed in to change notification settings

MatheusRich/rails-diff

Repository files navigation

Rails::Diff

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.

Installation

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

Usage

Compare specific files

# 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 generator files

# 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

Options

--fail-on-diff

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.

--commit <commit_hash>

Specify the commit hash you want to compare against. If not provided, the latest commit on main will be used by default.

--new-app-options

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"

How it works

When you run the diff, it will:

  1. Clone the latest Rails from main branch
  2. Generate a new Rails app with the same name as yours
  3. Show you a colored diff between your file and the generated one

Cache

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.

Development

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.

Contributing

Bug reports and pull requests are welcome on GitHub at /~https://github.com/matheusrich/rails-diff.

License

The gem is available as open source under the terms of the MIT License.

About

Compare Rails-generated files with the ones in your repository

Resources

License

Stars

Watchers

Forks

Packages

No packages published