Sometimes you need to use a gem that is only available in a private git repository. There are a few ways to do this:
- Install an SSH certificate on your server, but it's not always an option (for example, if you use Heroku)
- Use Gemfury, but that costs money and potentially creates privacy concerns
- Hard-code an oauth token into your Gemfile (if the gem is hosted on github), but then anyone with access to the code also has access to all of your github repositories
Vendorise offers a different way of accessing privately hosted gems, by using git's subtree command to download the gem on your development machine and commit it into the source tree of your repository.
By using subtree, updating the code is straightforward and your server does not need to have access to the private git repository. For more explanation about git subtree and why you'd want to use it, I recommend reading Alternatives To Git Submodule: Git Subtree.
Note: vendorise relies on the git subtree command to work - only recent versions of git have this
If you're using bundler add this line to your application's Gemfile:
gem 'vendorise', group: :development
Or if you don't use bundler:
$ gem install vendorise
rake "vendorise:gem[repo_url]"to vendorise the gem hosted at
gem '<gem_name>', path: 'vendor/gems/<gem_name>'to your Gemfile
You can update the gem at any time by running the rake task again.
By default the
vendorise:gem rake task will use the master branch. To use another branch (or tag) specify it as the second parameter, like this:
rake "vendorise:gem[repo_url, branch]"