mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Initializer provides its context class name
This commit is contained in:
parent
116f7a18b2
commit
9442239b45
3 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue