Easy8 initialisation order¶
The order in which Easy8 initialises. Use it to choose the right place for your initialisation code.
- Engine Initializers #1
- code in
lib/EngineName/engine.rb, e.g.lib/easy_b2b/engine.rb -
code that is not in any later blocks
-
Rails application initializers
config/initializers/*-
code that is not in any of the later blocks
-
Engines Initializers #2
-
initializer code blocks from
lib/EngineName/engine.rb -
Engines Initializers #3
-
config/initializers/* -
Rails.application.config.to_prepareblocks - These are run on every code reload in development mode
-
This block runs before patches are applied !!
-
Railtie.config.to_prepareblocks - These are run on every code reload in development mode
30-redmine.rbregisters a block that runsRedmine::Preparation.prepareand theafter_plugins_loadedhooks.33-easy_patches.rbapplies the Easy patches from anafter_plugins_loadedhook.-
EasyB2b::Engine.config.to_prepareruns after the plugin application if it is defined ineasy_b2b/config/initializers, and before patches if it is defined ineasy_b2b/lib/easy_b2b/engine.rb -
Rails.application.config.after_initializeblocks
Easy plugins (including your modification_<name> plugin) are loaded by EasyPluginLoader, which easy_engines/easy_extensions/config/initializers/x_easy_plugin_loader.rb calls from the initializers of the easy_extensions engine. It requires lib/<plugin_name>.rb and then every file in the plugin's config/initializers/, so plugin initializers run after the initializers of easy_extensions and before those of the other engines.
Example¶
1.
2.
# Rails.root/config/initializers/30-redmine.rb
puts "This is where plugins/PLUGIN_NAME/app/* + lib is added to autoload_paths"
3.
# my_engine/lib/my_engine/engine.rb
class Engine < ::Rails::Engine
initializer do
puts "Enqueued but runs very early"
end
end
4.
5.
# Rails.root/config/initializers/00-core_plugins.rb
Rails.application.config.to_prepare do
puts "This is before easy patch application"
end
6.
# my_engine/config/initializers/03_hooks.rb
Rails.application.config.to_prepare do
puts "This is before easy patch application"
end
7.
# my_engine/lib/my_engine/engine.rb
class Engine < ::Rails::Engine
config.to_prepare do
puts "This is still before easy patch application"
end
end
8.
# Rails.root/config/initializers/30-redmine.rb
Rails.application.config.to_prepare do
puts "In this block the after_plugins_loaded hooks run"
end
# Rails.root/config/initializers/33-easy_patches.rb
Rails.application.config.to_prepare do
puts "In this block we apply easy_patches"
end
9.
# my_engine/config/initializers/03_hooks.rb
MyEngine::Engine.config.to_prepare do
puts "Runs as #1 out of these 3"
end
Rails.application.config.to_prepare do
puts "Runs as #2 out of these 3"
end
MyEngine::Engine.config.to_prepare do
puts "Runs as #3 out of these 3"
end
10.
# my_engine/lib/my_engine/engine.rb
class Engine < ::Rails::Engine
config.after_initialize do
puts "This is the first after_initialize block"
end
end
11.
# Rails.root/config/initializers/0-easy.rb
Rails.application.config.after_initialize do
puts "After initialize block from core app"
end
12.