fguillen
fguillen

Reputation: 38888

gemspec dependencies definition and require conflict

I have a conflict between the gem dependencies definitions and the require of these gems.

I have this:

# Gemfile
source "http://rubygems.org"
gemspec

-

# my_gem.gemspec
$:.push File.expand_path("../lib", __FILE__)
require "my_gem"

Gem::Specification.new do |s|
  s.version = MyGem::VERSION
  # ...
  s.add_dependency "s3"
end

-

# /lib/my_gem.rb
require 'rubygems'
require 's3'

The conflict line is the s3 requirement because when I execute bundle install it complains because this gem is not installed yet.

The workaround is to comment this require, then execute bundle install and uncomment the require again what is not pretty at all.

Any suggestion is welcome, if you need more details to understand the problem please tell me.

Upvotes: 0

Views: 1129

Answers (2)

Guillermo
Guillermo

Reputation: 18224

1.- Do not require 'rubygems' in a library. Is like if a unix program requires apt-get, so no other system can't use your library.

2.- In the library, put your version in a separate file /lib/lib_name/version.rb and require that file on gemspec. Only that file, so you don't load your library and dependecies when trying to loading the gemspec.

Upvotes: 1

semmons99
semmons99

Reputation: 1244

First, don't require your entire gem in your gemspec. Move your version info to a path like "lib/my_gem/version.rb" and require that. Secondly, you shouldn't do a "require 'rubygems'" unless you're using the Rubygems API for some feature. There are some users that don't use Rubygems, and you shouldn't force them to use it unless necessary.

Upvotes: 3

Related Questions