Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the order that gems are loaded from within one of the gems

I have two gems "CoreGem" and "AddonGem". Addon Gem adds extra functionality which will overwrite the core 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]

But i'd want to do this from within the AddonGem.

Thanks

like image 332
montrealmike Avatar asked Aug 15 '13 20:08

montrealmike


People also ask

Does it matter what order gems are socketed?

99.9% of the time it does not matter, but there are some wierd fringe cases where it can. As has been mentioned, Triggered active gems trigger in the order they are socketed in the item. So for example, if you trigger desecrate and an offering, you want to have the desecrate go off first so that it makes corpses for the offering to consume.

How does the Order of active gems affect phase run?

If you want to activate Phase run off a trigger gem, you want it to be the last gem to activate because otherwise the next gem to activate will pull you out of the stealth&speed buff. for gems like "cast when.." or items with effects like this the order of active gems organises what gem is triggered first and what gem comes last. (right?) Right.

What level do gems stop in in order and Chaos Online?

In Order and Chaos Online Gems do not stop at level 4. There are many higher level gems. This article only concerns begening gems. Those are the basics of gems. You are sure to learn more about it in game and with experience. Do not skip this part of the game.

How do I list gems required for a project?

A list of gems required for a given (non-gem) project can be listed on a special file called “Gemfile” so they can be automatically installed by Bundler. Both covered later in this guide. What are some examples of gems?


1 Answers

Where railties_order is used

railties_order is used here:

https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L317

to determine the ordering of initializer blocks to run,

https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L337

found in other gems.

https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L47

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.

What you could do instead

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

So perhaps you can monkey-patch the Bootstrap module with some initializers? I guess that's your call.

like image 133
Farley Knight Avatar answered Sep 19 '22 14:09

Farley Knight