diff options
-rw-r--r-- | railties/lib/rails/initializable.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/tasks/initializers.rake | 2 | ||||
-rw-r--r-- | railties/test/initializable_test.rb | 5 |
3 files changed, 10 insertions, 3 deletions
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 085fbf64b2..292379e3f3 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -9,8 +9,6 @@ module Rails class Initializer attr_reader :name, :block - delegate :railtie_name, to: :@context - def initialize(name, context, options, &block) options[:group] ||= :default @name, @context, @options, @block = name, context, options, block @@ -36,6 +34,10 @@ module Rails return self if @context Initializer.new(@name, context, @options, &block) end + + def context_class + @context.class + end end class Collection < Array diff --git a/railties/lib/rails/tasks/initializers.rake b/railties/lib/rails/tasks/initializers.rake index fd66b27bcd..6522f2ae5a 100644 --- a/railties/lib/rails/tasks/initializers.rake +++ b/railties/lib/rails/tasks/initializers.rake @@ -1,6 +1,6 @@ desc "Print out all defined initializers in the order they are invoked by Rails." task initializers: :environment do Rails.application.initializers.tsort_each do |initializer| - puts "#{initializer.railtie_name}.#{initializer.name}" + puts "#{initializer.context_class}.#{initializer.name}" end end diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index ed9573453b..d4eafebfa4 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -174,6 +174,11 @@ module InitializableTests end end end + + test "Initializer provides context's class name" do + foo = Foo.new + assert_equal foo.class, foo.initializers.first.context_class + end end class BeforeAfter < ActiveSupport::TestCase |