I have two projects that are version controlled in their own respective private GitHub repositories.
One of them is a Rails app, and the other one is a Rails engine.
I do not want to expose the Rails engine as a public gem.
How can I declare my Rails app has a dependency on the engine in such a way that Heroku can resolve it?
You can use a private gem server like Gemfury. It is also a Heroku addon (free plan works fine for your case).
This way you'll be able to release versions of your gem. Works much like rubygems, but is private.
Assuming that your engine is a gem in a private Github repository, you can try this approach, which uses an OAuth token:
https://gist.github.com/masonforest/4048732
As noted in the comments, the version which involves hardcoding the OAuth token value in your Gemfile is less secure than using an environment variable.
You can vendor your engine by placing the source in the vendor folder, then in your Gemfile reference it by path:
# Gemfile
gem 'some_engine', path: 'vendor/some_engine'
Either directly copy-paste the source there, or use a Git submodule. Run bundle install and you should be set.
Related
I am trying to deploy APM solution provided by scout app. Scout apm documentation says I need to install a gem in all the applications I am running on the server. I have multiple applications running on single server. All my ruby applications are located at /var/www. Is there a way I can deploy that apm gem in one place and then it can be used for all the services. so that I don't need to add it in each application Gemfile and its config file in config folder. I know I can achieve it using a shell script however problem with that approach is all the apps have their own git repo which would be administrative overhead for me.
No, you have to add gems that you want to use in an application to the Gemfile. Because if you do not add that gem to an application's Gemfile then the application will simply not load that gem.
Another option might be to install the gem globally ion the server and require that gem in each application manually. But that still means you have to add a require 'gem_name' to all applications and this is error-prone because you lose the magic provided by bundler.
tl;dr: No, you have to add the gem to each application's Gemfile.
I'm working on a collaborative Rails project and I'd like to make use of Thoughtbot's excellent vim-rspec gem in my own development environment without polluting the project's Gemfile (not many of the collaborators use Vim).
vim.rspec recommends it is installed as a vundle. It isn't a gem but more of a plugin.
There are instructions to install vundle on the homepage. If you install it locally outside of the rails project it won't affect your collaborators.
The rails engines feature is pretty good, and I have watched the Railcasts and read the Rails documentation on it. I can see how you can access or override all the relevant components in the engine.
However, say I wanted to drastically modify the engine's code, is it possible to convert the engine back into a normal Rails app, and then take it from there. Is there anything else involved other than copying the directories in the gem over an empty application directory?
I am looking at this engine:
https://github.com/ging/social_stream
Yeah you can, just go to https://github.com/rails/rails & hit the fork button to fork the repository to your github account (assuming you already have one setup). Afterwards, clone the forked project to your local machine with:
git clone your_forked_repository_url.git
If you don't feel the need to fork your own version run:
git clone git://github.com/rails/rails.git
At this point you can make modifications to your heart's content. To use a local copy of the gem in a rails application add the following to your Gemfile (replacing the old rails gem):
gem "rails", :path => "/somewhere/your_rails_project"
All of this and more is highlighted in http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html
Page 239 of Agile Web Development with Rails instructs us to add the vendor/cache directory to git.
Is this actually recommended practice? I was under the impression that this directory was platform-specific. Will it cause problems to commit a cache dir under OSX and then deploy to prod under Linux?
This is where your app's gems are stored if you package them locally. So if you deploy from the SCM source and you want to use the exact gem packages that you are using locally, you'll need these files, which is why I suspect the book suggests this.
As far as the gem files go, it won't cause a problem if you develop on a Mac and deploy to a Linux server.
Short answer - yes.
Long answer - it's very handy to keep your gem dependencies with your application. Not just a Gemfile and Gemfile.lock but also the gems themselves.
There are numerous advantages - such as having all your gems available without having to connect to a gem server.
I've written a few gems that I've released to rubygems using Gemcutter and the source stored on github.
I have issue that I need to create a gem that can't be open source and also not available to the community, but only to members of my team.
I am aware that I can store gems locally and target them in my Gemfile, however I'd like to be able to do
rake version:bump
rake release
or similar. That would bump the version and push it to my gem server and still keep older gems so that people can install older versions of it.
Seems like it should be fairly simple to do. I'm just missing how to do it
This is fairly simple if you have a server you can host your private gems on. Setup a subdomain, something like gems.companyname.com and setup a virtual host to host your domain. You'd point that virtual host to a folder like you would any website and setup the gem server from there.
Example:
mkdir /var/www/gemserver
mkdir /var/www/gemserver/gems
cp private-gem-0.1.0.gem /var/www/gemserver/gems
cd /var/www/gemserver
gem generate_index
/var/www/gemserver would be the root directory. Lastly all you'd need to do is add a new source to your Gemfile
source 'http://rubygems.org'
source 'http://gems.companyname.com'
So anyone that knows about your custom domain can get access to the gems. The only pain is every time you rebuild your gem you need to run the generate_index command again after you upload your gem to the gems folder.