I have a question about the role of bundler when creating a gem. I'm
familiar with bundler and the way that it handles dependencies in a
rails app, but I've run into a few snags with using it to manage
dependencies for gems that I've created.
In a gemspec you can use `add_dependency` to include other gems as a
dependency for your gem. Random example:
Gem::Specification.new do |gem|
#...
gem.add_dependency 'json'
end
That means that installing my gem will also install json (if it doesn't
exist).
I have a question about the role of bundler when creating a gem. I'm
familiar with bundler and the way that it handles dependencies in a
rails app, but I've run into a few snags with using it to manage
dependencies for gems that I've created.
In a gemspec you can use `add_dependency` to include other gems as a
dependency for your gem. Random example:
Gem::Specification.new do |gem|
#...
gem.add_dependency 'json'
end
That means that installing my gem will also install json (if it doesn't
exist).
You can include all (runtime + development) dependencies in the
gemspec. Rubygems allows you to specify development dependencies with #add_development_dependency, to distinguish it from #add_runtime_dependency.
Yes, I know that you specify dependencies this way in the gemspec, but
my question is whether you can do the same using the Gemfile?
The reason I brought this up was because I incorrectly specified the
dependencies in my first gem. After doing `bundle gem ...` and seeing
the Gemfile I incorrectly assumed that my dependencies would go in that
Gemfile, in the same way that they do for a rails app.
I only learnt that this isn't the correct way to specify dependencies
after installing my gem on another machine.
I'm pretty sure `bundle new` isn't a thing. If it is for you, then maybe
you have an older version.
Urgh, my bad. I meant `bundle gem mygem`!
The gemspec is what tells it to look in mygem.gemspec for the
dependencies
list.
So does that mean that you don't add gems to the Gemfile unless you only
want them for development? And that any dependencies **have** to go in
the gemspec?
On Fri, Apr 5, 2013 at 7:07 AM, Jon Cairns <lists@ruby-forum.com> wrote:
> You can include all (runtime + development) dependencies in the
> gemspec. Rubygems allows you to specify development dependencies with
> #add_development_dependency, to distinguish it from
> #add_runtime_dependency.
Yes, I know that you specify dependencies this way in the gemspec, but
my question is whether you can do the same using the Gemfile?
You can include all (runtime + development) dependencies in the
gemspec. Rubygems allows you to specify development dependencies with #add_development_dependency, to distinguish it from #add_runtime_dependency.
On 5 April 2013 12:54, Jon Cairns <lists@ruby-forum.com> wrote:
So does that mean that you don't add gems to the Gemfile unless you only
want them for development? And that any dependencies **have** to go in
the gemspec?
The only things I put in the Gemfile would be if they were on Github and
not rubygems.
Here is an example of a Gemfile and gemspec where you can see how I do it.
-Josh
···
On Fri, Apr 5, 2013 at 6:54 AM, Jon Cairns <lists@ruby-forum.com> wrote:
Josh Cheek wrote in post #1104528:
> I'm pretty sure `bundle new` isn't a thing. If it is for you, then maybe
> you have an older version.
Urgh, my bad. I meant `bundle gem mygem`!
> The gemspec is what tells it to look in mygem.gemspec for the
> dependencies
> list.
So does that mean that you don't add gems to the Gemfile unless you only
want them for development? And that any dependencies **have** to go in
the gemspec?
I agree with you, but it seems there's a documentation mismatch on
docs.rubygems.org, not sure why but it's probably confusing to people: http://docs.rubygems.org/read/chapter/20
···
On 5 April 2013 13:31, Josh Cheek <josh.cheek@gmail.com> wrote: