如何更改从其中一颗宝石中加载宝石的顺序 [英] How to change the order that gems are loaded from within one of the gems
问题描述
我有两个宝石CoreGem"和AddonGem".Addon Gem 添加了额外的功能,将覆盖核心 gem.
I have two gems "CoreGem" and "AddonGem". Addon Gem adds extra functionality which will overwrite the core gem.
我如何确保如果添加第二个 gem 它将覆盖第一个的视图和资产.
How do i make sure that if the second gem is added it will overwrite the views and assets of the first.
到目前为止,它在添加到主应用程序时有效:
So far it works when adding to the main app:
config.railties_order = [ :main_app, AddonGem::Engine, :all]
但我想从 AddonGem 中执行此操作.
But i'd want to do this from within the AddonGem.
谢谢
推荐答案
railties_order
的使用场合
railties_order
在这里使用:
Where railties_order
is used
railties_order
is used here:
https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L317
确定要运行的 initializer
块的顺序,
to determine the ordering of initializer
blocks to run,
https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L337
在其他宝石中发现.
https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L47
因此在 initializer
块中设置 railties_order
将毫无意义,因为在调用 initializer
块时,railties_order
已经设置并被应用程序的其余部分使用.
So setting railties_order
inside an initializer
block would be rather pointless, as by the time the initializer
block was called, railties_order
was already set and is in used by the rest of the application.
显然在 Rails::Application::Bootstrap
中还有更多的 initializer
块.
Apparently a bunch more initializer
blocks are inside the Rails::Application::Bootstrap
.
https://github.com/rails/rails/blob/master/railties/lib/rails/application/bootstrap.rb
那些在主应用程序的初始化块之前:
Those are prepended before the main application's initializer blocks:
https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L262
那么也许您可以使用一些初始化程序来修补 Bootstrap 模块?我想这是你的电话.
So perhaps you can monkey-patch the Bootstrap module with some initializers? I guess that's your call.
这篇关于如何更改从其中一颗宝石中加载宝石的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!