How to add additional gems inside a RubyGem package? - ruby-on-rails

I am going through the documentation at http://guides.rubygems.org/ to learn about RubyGems.
My goal is to package a Ruby application (no executables) which depends on some other Gems (for example, say, Rails!).
I am not a Ruby expert so I am confused and have the following two questions:
How can I add the Gem inside the package to be shipped with my app?
Should I instead not add the gem inside but create dependencies list, which is to be executed upon installation of my gem?
What is the right way to ship dependencies with my gem?
Thanks!

Each gem has a gemspec file where the dependencies are specified. Use bundle to install the gem and it will also install the dependencies.

Related

Is there a command in Rails that installs all your gems and dependencies?

I am learning Ruby on Rails and I find it annoying having to install and worry about gems and other dependencies for the apps I build . Does Rails have a way to install all your gems and dependencies for you ?
Yes. You have a file called Gemfile in the directory of your application.
Put all the gem you want to use in it.
And then just run bundle install to install all in one time (with dependencies) and later bundle update to update all your gem installed.
You can see Bundler: The best way to manage a Ruby application's gems and Ruby on Rails Tutorial for more informations.

How can I find out what gem is dependent on termios in my Gemfile?

I have updated all of my gems, including to Rails 3.2.8, prior to a new deployment. However, my application is now broken because something is trying to install gem "termios" version 0.9.4.
Apparently, 0.9.4 does not work on any computer or server I own. There are some newer versions, 0.9.6 specifically, but they are not posted in wherever bundler looks for gems.
There are some version on Github, but they have been mysteriously renamed "ruby-termios". Well, some gem in my Gemfile is not looking for ruby-termios. It's looking for termios. Failure.
How can I find out which gem is trying to install this so I can see if it can be whacked?
Check your Gemfile.lock - it has all the gems and their dependencies listed in it. As long as you've been able to install these gems in the past, you'll be able to tell where that dependency is coming from.
The gem command will dump out the tree of dependencies for you.
$ gem dependency
Or if you want to check just a specific gem.
$ gem dependency foo

Could not find gem 'spree-paypal-express' with spree 1.1.1

Hi I have installed and working Spree 1.1.1. and want to integrate PayPal to the engine. and when i am trying to install 'spree_paypal_express' the console is showing the below message please help me out.
Could not find gem 'spree-paypal-express (>= 0) x86-mingw32' in the gems available on this machine.
There are a few possible issues with this.
First, there may be an issue with your Gemfile. For example,
-- the gem may not be in the gemfile,
-- you may have misspelled the name of the gem in your gemfile
-- you may have extra whitespace in the gem name (e.g., gem 'spree-paypal-express ' <- note extra space)
Here are some things you can try (after checking the above first to make sure your Gemfile is correct):
Remove all your gems (go to the gems folder of your ruby, remove the specifications folder and the gems folder -- or create a new gemset using rvm)
gem list should be more or less empty
gem install bundler
And try to bundle install again from scratch.
I have manually downloaded zip folder from github repository and extracted.
by going in to the directory run gem build spree_paypal_express.gemspec
then it will generate some files in which spree_paypal_express-1.1.0.gem will be one of them.
so later run gem install spree_paypal_express-1.1.0.gem
then you are ready to go... you can check by gem list

Do you need to install a gem for each separate rails app

Like the title says, if I use a gem in one app (install it, add to Gemfile, etc.) do I still have to run gem install xxx in a new app?
Unless you're not using Bundler, you very rarely need to run gem install ... at all, actually.
More often than not, unless you're using different Rubies for each of your projects, all of your gems live in folders that get shared across all of the projects that use them. If you're using rvm you can see this directory by running rvm gemdir.
When you use Bundler, it will automatically handle loading the appropriate version of the gem in the (likely) case that you have several versions installed.
No.
In fact, for a modern (Rails 3+) app you should never need to run gem install (except, of course, for the initial gem install bundler rails that you need to do once), you should just add the gem to your Gemfile and then run bundle install. Let Bundler take care of dependencies and installing for you, that's what it's there for.

Initialize a Rails 3 plugin gem on installation

I'm creating a RubyGem, and I'm wondering if there's any way I can set it up so that when it's listed in a Gemfile and someone runs bundle install, my gem can copy some files into the Rails path. This would save the user from having to type rails generate blah, where blah is the name of a generator in my gem.
Is there a callback that the current version of Bundler runs when it installs a gem?
The gem is installed system-wide so it has no knownledge of the project you are using.
The only way to accomplish this is to package it as a plugin and install it as plugin, not a gem. In this case you can provide an install.rb hook.

Resources