Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gem dependency to my ruby gem

Tags:

ruby

gem

lita

I think I am fundamentally missing something. I am learning ruby, and have been playing with Lita lately, and wrote(my first) a simple little gem to get some directions/distance from the bot. The problem I am having is where to put a gem dependency in my gem. To work, my gem requires the 'rest-client' gem. Where do I put this in my code so that it is available to my Directions class? Currently, to get it to run, I am requiring the gem in my bots actual gemfile. And when I bundle exec lita, it apparently becomes available for my gem to use... but if I remove it from there, I can't get it to work anywhere in my gem.. what am I missing? It is here if anyone wants to read the code and tell me where I should be adding it:

https://github.com/cashman04/lita-directions

EDIT: I added the dependency like spickermann suggested. Then had to add require 'rest-client'to my directions.rb. Not entirely sure if this is the correct way, but it works now. Thanks for the help spickermann

like image 883
cashman04 Avatar asked Jan 28 '15 00:01

cashman04


People also ask

How do I add gems to Ruby?

Including A Gem Within a Ruby Program. To install and make use of a gem, within a ruby program, the command is simple. gem install 'NameOfGem' I will use Faker as an example for the rest of this post. So to install the Faker gem I would run the command, gem install faker .

How do I resolve gem dependencies?

Common Attempts To Resolve Ruby Gem Dependencies Bundler can help to resolve dependencies when working with Ruby gems by allowing you to specify a set of gems in a Gemfile, then issue a single command to install them. Bundler then automatically resolves the dependencies for you.

How do I install gem packages?

To install a gem, use gem install [gem] . Browsing installed gems is done with gem list . For more information about the gem command, see below or head to RubyGems' docs. There are other sources of libraries though.


1 Answers

Put the following line into your lita-directions.gemspec right next to the one that defines the dependency on lita:

spec.add_runtime_dependency 'rest-client'
like image 148
spickermann Avatar answered Oct 20 '22 14:10

spickermann