Вопрос

I'm developing a rails 4 engine (gem name: tax_cloud_for_spree) for a spree 2.1 application I've developed (also rails 4). This new engine has a gem dependency on the "tax_cloud" gem. I'm not able to require this dependency; attempting to start the rails server yields:

/Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require': cannot load such file -- tax_cloud (LoadError)
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/jackryon/Documents/rails_dev/tax_cloud_for_spree/lib/tax_cloud_for_spree/engine.rb:1:in `<top (required)>'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/jackryon/Documents/rails_dev/tax_cloud_for_spree/lib/tax_cloud_for_spree.rb:1:in `<top (required)>'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /Users/jackryon/Documents/rails_dev/purible2/config/application.rb:7:in `<top (required)>'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
    from /Users/jackryon/.rvm/gems/ruby-2.0.0-p247@purible2/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

I'm currently requiring the tax_cloud gem at the top of my "lib/tax_cloud_for_spree/engine.rb" file, and the gemspec adds the runtime dependency like:

Gem::Specification.new do |s|
  ...
  s.add_runtime_dependency "tax_cloud", "0.2.2"
end

It seems that the lib directory from tax_cloud is not able to be loaded by my require. I'm using bundle config.local to set my path to the engine to a local git repository while I'm actively developing it.

Running "bundle show tax_cloud_for_spree" shows

~/Documents/rails_dev/tax_cloud_for_spree

and bundle show tax_cloud gives

~/Documents/rails_dev/tax_cloud_for_spree

so, it would seem as though the tax_cloud gem is successfully installed in this gemset, and available to be required.

Is there some config.autoload_paths call I need to make, or perhaps an initializer hook I could block into to require this gem?

Another note is that I'm able to start the server if I add the tax_cloud gem directly to the parent application's gemfile. I'd much prefer to have my engine manage its own dependencies, though, for obvious reasons. Should I consider writing a generator to add the gem to the parent app's gemfile? This approach also seems clunky.

Any help on this is greatly appreciated.

EDIT

I think that the crux of my dilemma is this:
Is it possible to require a bundled gem from an rvm gemset..
into a gem that is pathed to a config.local path..
that is then loaded into a rails application?

This would make it possible to develop the gem in the context of my application, while leveraging the third party gem. Anybody?

Это было полезно?

Решение

I'm using bundle config.local to set my path to the engine to a local git repository while I'm actively developing it.

This is a Bundler-specific extension to the normal Rubygems behaviour. Rubygems doesn't know anything about it, so when it installs your engine, it will use the normal Rubygems dependency resolution process and expect to find tax_cloud on rubygems.org.

The only way to do what you want is what you have already discovered: adding the tax_cloud gem directly to the Gemfile of your application.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top