简体   繁体   English

在Ruby on Rails中,安装gem或插件之间的区别是什么?

[英]In Ruby on Rails, what's the difference between installing something as a gem or as a plugin?

On http://github.com/collectiveidea/delayed_job http://github.com/collectiveidea/delayed_job上

it says: 它说:

To install as a gem, add the following to config/environment.rb: 要安装为gem,请将以下内容添加到config / environment.rb:
config.gem 'delayed_job'
Run rake gems:install 运行rake gems:install

versus

To install as a plugin: 要作为插件安装:
script/plugin install git://github.com/collectiveidea/delayed_job.git

What is the difference between installing it as a gem or as a plugin? 将它安装为gem还是作为插件有什么区别?

Also, the first method just install gem 2.0.3 which might be the tobi's version? 另外,第一种方法只是安装gem 2.0.3,这可能是tobi的版本? ( rake gems:install installs the version by gem list -r delayed_job ) Is it http://github.com/tobi/delayed_job ? rake gems:install通过gem list -r delayed_job安装版本)是http://github.com/tobi/delayed_job吗? The "plugin" method specifically says it is the collectiveidea version? “插件”方法明确表示它是集体版本? Doesn't it matter which one you install? 你安装哪一个不重要吗?

Both the Gem and the vendored plugin refers to the collectiveidea's fork. Gem和vendored插件都指的是collectiveidea的分叉。 In fact, collectiveidea is the current maintainer for the delayed_job Gem on RubyGems. 事实上,collectiveidea是RubyGems上delayed_job Gem的当前维护者。

That said, generally speaking installing a plugins as a Gem has many advantages. 也就是说,一般来说,将插件安装为Gem有许多优点。

  • You can install it once and use it in many different projects 您可以安装一次并在许多不同的项目中使用它
  • You can take advantage of dependency resolution 您可以利用依赖项解析
  • You can upgrade just changing version number 您只需升级版本号即可升级
  • You don't need to store the entire plugin code in your SCM 您无需将整个插件代码存储在SCM中

So, why you can install a plugin "as a plugin"? 那么,为什么你可以“插件”安装一个插件? There are many different answers. 有许多不同的答案。

At the very beginning, Rails plugins came as simple libraries. 一开始,Rails插件就像简单的库一样。 Time passes and developers started to notice the advantage of packaging plugins as Gem. 时间过去了,开发人员开始注意到将插件打包为Gem的优势。

Also, before Rails 3, some plugin features were only reserved to plugins and not to Gems. 此外,在Rails 3之前,一些插件功能仅保留给插件而不保留给Gems。 For instance, before Rails 3, plugins could bundle rake tasks while there wasn't a way to inject new rake tasks or new routes into the main application. 例如,在Rails 3之前,插件可以捆绑rake任务,而没有办法将新的rake任务或新路由注入主应用程序。

In the last two years, the most part of Rails plugins offers the ability to be installed as a plugin or as a Gem. 在过去两年中,Rails插件的大部分内容都提供了作为插件或Gem安装的能力。 With Rails 3 and the arrival of Bundler, I'm sure plugins are going to be deprecated in favor of Gems. 随着Rails 3和Bundler的到来,我确信插件将被弃用以支持Gems。

That are 2 different repositorys, maybe you shoult try 这是两个不同的存储库,也许你应该尝试

config.gem 'delayed_job', :source => http://github.com/collectiveidea/delayed_job.git

Look at: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies 请看: http//ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies

Btw. 顺便说一句。 maybe you want to look at a maybe better solution: resque - see http://ruby-toolbox.com/categories/queueing.html for a comparison of used queing gems 也许你想看一个更好的解决方案:resque - 请参阅http://ruby-toolbox.com/categories/queueing.html以比较使用过的排队宝石

当您安装gem时,它将适用于所有应用程序,以防您使用插件 - 仅适用于已安装的应用程序。

The basic difference is a gem is something that gets installed on the system running your Rails application, whereas a plugin is installed along with your application, plugin does not get installed on the system level. 基本的区别是gem是安装在运行Rails应用程序的系统上的东西,而插件是与您的应用程序一起安装的,插件不会安装在系统级别上。

suppose you are using rvm and let us take this example. 假设你正在使用rvm,让我们举个例子。

we have two applications app1 and app2 我们有两个应用程序app1app2

both are running on a common rvm gemset named gemset1 两者都运行在一个名为gemset1的常见rvm gemset

when you add a gem in the gemfile of app1 and run bundle install and then being in the same rvm gemset which is gemset1 , if you run the second app app2 the gem will be available in the second application as well 当你在app1的gemfile中添加一个gem并运行bundle install然后在同一个rvm gemset是gemset1时 ,如果你运行第二个app app2,那么gem也将在第二个应用程序中可用

Whereas with the plugin it will not be the case because plugins get installed on application level and not at the system level 虽然插件不是这种情况,因为插件安装在应用程序级别而不是系统级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM