Once upon a time, I needed to build a Rails app around a closed-source gem. My first reaction was to copy the gem’s source code directly into the vendor directory of the Rails app, but I figured there is a better way: Git submodules.
For this method to work, both the gem and the Rails application must be tracked in Git.
cd into your Rails app directory and then enter the command
git submodule and provide the URL to the Git repository and the directory in
which you want the submodule.
You ought to install your gem in the
vendor directory. The
lib directory is
intended for tasks and other things that you would think belong elsewhere.
Next, build the gem in the directory
Add the gem to the Gemfile of the Rails app. You must provide both the gem version and the path to the submodule.
bundler to install the gem.
Keep submodules current
Git provides a simple command to update all submodules to the latest commit of their respective repositories.