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

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

问题描述

我试过这样:

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

like add gem in the gemfile, 但是不起作用,会导致这个错误:

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 

推荐答案

可能无法添加本地依赖项,因为其他用户将无法访问 gem,因为它是本地依赖项,因此在发布后无用.取而代之的是,在您自己的插件的 gemspec 中添加远程依赖项.

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.

步骤 -

1) 在vendor/plugins/my_plugin/中打开自己插件的gemspec文件,在关键字end前添加:

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

(在本例中,我使用了 my_plugin 的 will_paginate 所需依赖项)

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

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

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

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

3) 现在在 rails app root 中做:

3) Now in rails app root do:

bundle install

并安装了 my_plugin 的依赖项(在本例中为 will_paginate).

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

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

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