diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2011-11-22 23:26:27 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2011-11-23 21:36:33 +0100 |
commit | 40b19e063592fc30705f17aafe6a458e7b622ff2 (patch) | |
tree | 65f2617b16d37c97217868771f72caaecaec6a9c /railties/lib | |
parent | 8549f7a4f0c30c37050666f5661ea9e270a298fd (diff) | |
download | rails-40b19e063592fc30705f17aafe6a458e7b622ff2.tar.gz rails-40b19e063592fc30705f17aafe6a458e7b622ff2.tar.bz2 rails-40b19e063592fc30705f17aafe6a458e7b622ff2.zip |
Allow to change engine's loading priority with config.railties_order=
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 22 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 24 |
3 files changed, 47 insertions, 4 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0b72a7ed84..847445d29f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -127,6 +127,28 @@ module Rails }) end + def ordered_railties + @ordered_railties ||= begin + order = config.railties_order.map do |railtie| + if railtie == :main_app + self + elsif railtie.respond_to?(:instance) + railtie.instance + else + railtie + end + end + + all = (railties.all - order) + all.push(self) unless all.include?(self) + order.push(:all) unless order.include?(:all) + + index = order.index(:all) + order[index] = all + order.reverse.flatten + end + end + def initializers Bootstrap.initializers_for(self) + super + diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8f5b28faf8..e95b0f5495 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -10,8 +10,8 @@ module Rails :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, - :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils + :ssl_options, :static_cache_control, :session_options, + :time_zone, :whiny_nils, :railties_order attr_writer :log_level attr_reader :encoding @@ -35,6 +35,7 @@ module Rails @middleware = app_middleware @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 335a0fb1b5..5c1af99fe2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -330,6 +330,17 @@ module Rails # # MyEngine::Engine.load_seed # + # == Loading priority + # + # In order to change engine's priority you can use config.railties_order in main application. + # It will affect the priority of loading views, helpers, assets and all the other files + # related to engine or application. + # + # Example: + # + # # load Blog::Engine with highest priority, followed by application and other railties + # config.railties_order = [Blog::Engine, :main_app, :all] + # class Engine < Railtie autoload :Configuration, "rails/engine/configuration" autoload :Railties, "rails/engine/railties" @@ -480,10 +491,19 @@ module Rails @routes end + def ordered_railties + railties.all + [self] + end + def initializers initializers = [] - railties.all { |r| initializers += r.initializers } - initializers += super + ordered_railties.each do |r| + if r == self + initializers += super + else + initializers += r.initializers + end + end initializers end |