简体   繁体   English

gem依赖项的Railtie初始化

[英]Railtie initialization of gem dependencies

I am trying to understand the initialization process for Rails 3 plugins. 我正在尝试了解Rails 3插件的初始化过程。 I have a plugin packaged as a gem that I am including in my Gemfile for my project. 我有一个打包为gem的插件,该插件包含在我的项目的Gemfile中。

In turn, that gem specifies in its gemspec that it depends Sunspot::Rails. 反过来,该gem在其gemspec中指定它依赖Sunspot :: Rails。 The gem itself gets pulled in and I can access its classes, but it doesn't appear that the railtie initialization code gets run. gem本身被拉进去,我可以访问它的类,但是似乎并没有运行railtie初始化代码。

However, if I add a line in my project's Gemfile for sunspot_rails directly, then the initialization code is run. 但是,如果直接在项目的Gemfile中为sunspot_rails添加一行,则将运行初始化代码。

Does anyone know of a way to have my gem/plugin run the initialize code in its dependencies without having to include all of them directly in my project? 有谁知道让我的gem / plugin在其依赖项中运行初始化代码而不必将所有这些都直接包含在我的项目中的方法吗?

Thanks in advance. 提前致谢。

After reading the above article and responses , I realized that I was requiring sunspot/rails instead of sunspot_rails . 阅读以上文章和回复后 ,我意识到我需要的是sunspot_rails sunspot/rails而不是sunspot_rails It's necessary to require sunspot_rails because that in turn requires the railtie (which is not automatically required as part of having the gem listed in the gemspec). 需要sunspot_rails是必要的,因为这反过来又需要railtie(在gemspec中列出宝石时,它不会自动被要求)。

Here is a link to a very good article on the difference between gemspec and Gemfile that helped explain it all. 这是一篇非常好的文章的链接,该文章很好地解释了gemspec和Gemfile之间的区别。

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

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