需要gem依赖于rails引擎开发(使用bundler config.local)

时间:2013-12-30 18:55:09

标签: ruby-on-rails-4 gem bundler spree rails-engines

我正在为我开发的spree 2.1应用程序(也是rails 4)开发一个rails 4引擎(gem name:tax_cloud_for_spree)。这个新引擎对“tax_cloud”gem有一个gem依赖。我不能要求这种依赖;尝试启动rails服务器产生:

/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>'

我目前要求在我的“lib / tax_cloud_for_spree / engine.rb”文件的顶部使用tax_cloud gem,gemspec会添加运行时依赖项,如:

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

似乎来自tax_cloud的lib目录无法由我的require加载。我正在使用bundle config.local将我的引导路径设置为本地git存储库,同时我正在积极开发它。

运行“bundle show tax_cloud_for_spree”显示

~/Documents/rails_dev/tax_cloud_for_spree

和捆绑show show tax_cloud给出

~/Documents/rails_dev/tax_cloud_for_spree

所以,似乎tax_cloud gem已经成功安装在这个gemset中,并且可以被要求。

我需要调用一些config.autoload_paths调用,或者可能是一个初始化器挂钩我可以阻塞来要求这个gem吗?

另一个注意事项是,如果我将tax_cloud gem直接添加到父应用程序的gemfile,我就可以启动服务器。不过,出于显而易见的原因,我更喜欢让我的引擎管理它自己的依赖项。我应该考虑编写一个生成器来将gem添加到父应用程序的gemfile中吗?这种做法看起来也很笨拙。

非常感谢任何帮助。

修改

我认为我的困境的关键在于:
是否有可能需要一个rvm gemset的捆绑宝石。
进入一个pathed到config.local路径的宝石。
然后将其加载到rails应用程序中?

这样就可以在我的应用程序环境中开发gem,同时利用第三方gem。任何人

1 个答案:

答案 0 :(得分:0)

  

我正在使用bundle config.local将我的引导路径设置为本地git存储库,而我正在积极开发它。

这是针对普通Rubygems行为的Bundler特定扩展。 Rubygems对此一无所知,因此在安装引擎时,它将使用正常的Rubygems依赖项解析过程,并期望在rubygems.org上找到tax_cloud

实现目标的唯一方法就是您已经发现的内容:将tax_cloud gem直接添加到应用程序的Gemfile