diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/initializable.rb | 29 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 2 |
2 files changed, 13 insertions, 18 deletions
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index d91f67823f..9a82e051e7 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -1,3 +1,5 @@ +require 'tsort' + module Rails module Initializable def self.included(base) @@ -30,29 +32,21 @@ module Rails end class Collection < Array + include TSort + + alias :tsort_each_node :each + def tsort_each_child(initializer, &block) + select { |i| i.before == initializer.name || i.name == initializer.after }.each(&block) + end + def initialize(initializers = []) - super() - initializers.each do |initializer| - if initializer.before - index = index_for(initializer.before) - elsif initializer.after - index = index_for(initializer.after) - index += 1 if index - else - index = length - end - insert(index || -1, initializer) - end + super(initializers) + replace(tsort) end def +(other) Collection.new(to_a + other.to_a) end - - def index_for(name) - initializer = find { |i| i.name == name } - initializer && index(initializer) - end end def run_initializers(*args) @@ -87,6 +81,7 @@ module Rails def initializer(name, opts = {}, &blk) raise ArgumentError, "A block must be passed when defining an initializer" unless blk + opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] } initializers << Initializer.new(name, nil, opts, &blk) end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 881c97f02d..64d03e7599 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -43,7 +43,7 @@ module Rails @config ||= Engine::Configuration.new end - initializer :load_init_rb do |app| + initializer :load_init_rb, :before => :load_application_initializers do |app| file = Dir["#{root}/{rails/init,init}.rb"].first config = app.config eval(File.read(file), binding, file) if file && File.file?(file) |