如何将本地gem的依赖项添加到.gemspec文件中的rails插件/引擎中 [英] How to add dependency of a local gem to a rails plugin/engine, in .gemspec file

查看:1388
本文介绍了如何将本地gem的依赖项添加到.gemspec文件中的rails插件/引擎中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以这种方式尝试过:

  s.add_dependency'gem',:path => '../gem'

喜欢在 gemfile中添加gem, code>但它不工作,并将导致此错误:

  /Users/chenqh/.rvm/ rubies-ruby-1.9.3-p194 / lib / ruby​​ / site_ruby / 1.9.1 / ruby​​gems / requirements.rb:81:在`parse'中:Illformed需求


解决方案

可能无法添加本地依赖关系,因为其他用户将无法访问宝石,因为它是本地依赖的,因此发布后没有用。而不是在您自己的插件的gemspec中添加远程依赖。



步骤 -



1)在 vendor / plugins / my_plugin / 中打开您自己的插件的gemspec文件,然后在关键字结束之前添加:

  s.add_dependency('will_paginate','〜> 3.0.pre2')

(在这个例子中,我使用了will_paginate需要依赖my_plugin)



2)现在进入你的rails应用程序并编辑Gemfile,添加:

  gem'my_plugin',,path =>'vendor / plugins / my_plugin'

3)现在在rails应用程序根目录中:

  bundle install 

安装了my_plugin(在这种情况下为will_paginate)的依赖关系。 p>

I had tried in this way:

 s.add_dependency 'gem', :path => '../gem'

like add gem in the gemfile, but it doesn't work, and will cause this error:

/Users/chenqh/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:81:in `parse': Illformed requirement 

解决方案

It's likely not possible to add local dependencies because other users will not be able to access the gem as it is local dependent and hence of no use after publish. Instead of that, Add remote dependency in your own plugin's gemspec.

Steps -

1) Open gemspec file of your own plugin in vendor/plugins/my_plugin/ and add before the keyword end:

s.add_dependency('will_paginate', '~> 3.0.pre2')

(In this example I have used will_paginate required dependency of my_plugin)

2) Now go in your rails app and edit Gemfile, add:

gem 'my_plugin', :path=>'vendor/plugins/my_plugin'

3) Now in rails app root do:

bundle install

And dependency of my_plugin (will_paginate in this case) is installed.

这篇关于如何将本地gem的依赖项添加到.gemspec文件中的rails插件/引擎中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆