문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top